I use the following macros in my code:
#define MAKE_FLAG_TYPE1(TYPE_NAME, F1) \
enum TYPE_NAME { F1 }; \
\
::std::ostream& operator<<(::std::ostream& os, TYPE_NAME f) \
\
switch(f) \
{ \
case F1: return os << #F1; \
} \
return os << "unknown"; \
}
[2, 3 and 4 argument versions]
#define MAKE_FLAG_TYPE5(TYPE_NAME, F1, F2, F3, F4, F5) \
enum TYPE_NAME { F1, F2, F3, F4, F5 }; \
\
::std::ostream& operator<<(::std::ostream& os, TYPE_NAME f) \
{ \
switch(f) \
{ \
case F1: return os << #F1; \
case F2: return os << #F2; \
case F3: return os << #F3; \
case F4: return os << #F4; \
case F5: return os << #F5; \
} \
return os << "unknown"; \
}
I wanted to try and do it with the Preprocessor library. It should be
something like this:
#include