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. – Lightness Races in Orbit Jul 25 '13 at 9:44enable_if
orconditional
to conditionally define typedefs, but you can't use preprocessor for that. – Bartek Banachewicz Jul 25 '13 at 9:44sizeof
cannot work in a preprocessor conditions is because the language is defined that way, not because of how an implementation works. – Eric Postpischil Aug 28 '13 at 15:16