I have this bit of code that helps me convert enum to string and vice versa.
So I wrote a macro to make it look better and simpler:
#define SMART_REVERT_CASE(__CODE__, __STRING__)\
if (__STRING__ == #__CODE__) return __CODE__
And then I call it this way:
enum EXAMPLE { HELLO, GOODBYE, ERROR };
EXAMPLE StringToExample(std::string const& input)
{
SMART_REVERT_CASE(HELLO, input);
SMART_REVERT_CASE(GOODBYE, input);
return ERROR;
}
Unfortunately it does not compile (on VS 2008):
Error 1 error C2666: 'operator ==' : 5 overloads have similar conversions
Is there a way to give a hint to the compiler as to which operator== to use ?
Just use:
BTW, using double underscores is a bad idea.
The C++11 draft n3290 defines the relevant
operator==as:so
compareand==are the same thing here.