Is there a way to do the if/else chain without starting with an if(0)?
I don't know of a better way to generate an if-else chain with macros. I agree it does look a little hacky.
However, here's another way way to validate that this string is one in the set built from X-Macros that compiles for C++14. Up to your taste if you think its better or not for your codebase.
#include <set>
#include <string>
void validate_string(std::string some_thing) {
/* Build the set of strings to test against with X-Macros */
static const std::set<std::string> validate_set = {
#define X(name) #name,
MY_LIST
#undef X
};
if (validate_set.find(some_thing) != validate_set.end()){
/* Then some_thing is one of the compile time constants */
}
}