I am trying to do something like this:
#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;
}
but I get this error:
error: missing binary operator before token "("
How can I correctly make the conditional typedef?
sizeof
, or other C++ constructs. It certainly doesn't know about things you created yourself withtypedef
, as that hasn't even been parsed yet.enable_if
orconditional
to conditionally define typedefs, but you can't use preprocessor for that.sizeof
cannot work in a preprocessor conditions is because the language is defined that way, not because of how an implementation works.