I've got a list of tokens from which I'd like to create an enum (trivial) and an array of strings (to be later used to create a map of string to enum). Here's my attempt:
#define TOKEN_LIST CUBE , SPHERE , CIRCLE
#define CREATE_ARRAY_OF_STRINGS( ... ) const char* token[] = { __VA_ARGS__ };
CREATE_ARRAY_OF_STRINGS( TOKEN_LIST )
// enum SHAPE_TYPE{ TOKEN_LIST }; // easy
int main(int argc, char *argv[])
{
return 1;
}
The problem is that the TOKEN_LIST is not stringified as shown when I compile with the -E flag as follows:
const char* token[] = { CUBE , SPHERE , CIRCLE };
int main(int argc, char *argv[])
{
return 1;
}
Where const char* token[] = { CUBE , SPHERE , CIRCLE }; should be const char* token[] = { "CUBE" , "SPHERE" , "CIRCLE" };
Is there any other way to achieve this with C++03? Boost Processor perhaps?