我想做这样的事情:
#include <iostream>
#include <random>
typedef int Integer;
#if sizeof(Integer) <= 4
typedef std::mt19937 Engine;
#else
typedef std::mt19937_64 Engine;
#endif
int main()
{
std::cout << sizeof(Integer) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
error: missing binary operator before token "("
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确地创建条件typedef?
是否可以在预处理程序指令中使用非类型常量模板参数?这就是我的想法:
template <int DING>
struct Foo
{
enum { DOO = DING };
};
template <typename T>
struct Blah
{
void DoIt()
{
#if (T::DOO & 0x010)
// some code here
#endif
}
};
Run Code Online (Sandbox Code Playgroud)
当我尝试使用类似的东西时Blah<Foo<0xFFFF>>,VC++ 2010会抱怨我们尝试使用的行中无法匹配的括号#if.我猜测预处理器并不真正知道任何关于模板的事情,这种事情只是不在其领域.说啥?