Amo*_*mum 5 c++ templates c++11
C++ 17具有这个很好的功能,允许您使用auto关键字声明非类型模板参数:
template<auto a>
void foo();
Run Code Online (Sandbox Code Playgroud)
它允许推导出这种参数类型,如下所示:
foo<3>() <-- a has deduced type of 'int'
Run Code Online (Sandbox Code Playgroud)
不幸的是,我必须使用不支持C++ 17的编译器,并且不完全支持C++ 11(它缺乏对标准库的支持).所以我的问题是:使用C++ 11可以达到同样的效果吗?
我能提出的唯一方法是使用宏:
template< typename T, T a>
void foo();
#define CALL_FOO( x ) foo< decltype(x), x >()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |