Can I use the typeid / type_info somehow to detect whether some type is an enum (any enumerator) ?
the following works fine to detect whether a variable has type int
template<typename T>
bool is_int( T var )
{
return strcmp( typeid(T).name(), typeid(int).name() ) == 0;
}
but I can't use a similar version for enums - the string returned by name() differs between Linux and Windows
template<typename T>
bool is_enum( T var )
{
// can I use typeid here?
// eg. string_contains( typeid(var).name(), "enum" );
}
I've seen the templated version in Boost, but we can't use this library yet...
strcmpon thename()s;std::type_infosupports comparison operators. Besides, the name of any type might differ from one platform to the next.is_enum(T)using simple tools. No Boost, no C++11. Perhaps something of the sortif( !is_int(T) && !is_pointer(T) && sizeof(T)==sizeof(some_dummy_enumerator) ) return true;- sorry about the syntax; I hope you understand what I'm trying to achieve