I am trying to create a type declaration based on boundaries
template<class B>
struct IntDecl {
enum {
L = B::_l, U = B::_u
};
#if (L >=0 && U <=255)
typedef char Type;
#elif (L>=0&&U<=65535)
typedef unsigned int Type;
#endif
};
So, as you see here depending on the value of L
and U
the type will be defined.
for example
IntDecl< BOUND < 0, 65535 > >::Type i; // this should be a unsigned int
IntDecl< BOUND < 0, 255 > >::Type i1; // this should be a char
The problem is , both ( i
and i1
) are considered chars
, in other words the #elif
is being discarded. any help? why #elif
is not executing?
The preprocessor pass happens before semantic analysis and enum is a semantic construct. You need to use templates to implement this, or make L
and U
macros that define preprocessor constants.