Note that in the latter instance, the default initialized value FloatFormat() is a valid enum value even though, being 0, there is no name for it in the list, and the named values are not consecutive.
Instead of generating an array of # member, I would suggest generating an array of {EnumName::member, # member} pairs. Then getValue can search for the name and return the corresponding EnumName. I think you also need a fallback if there is no name for the default initialized value EnumName(), perhaps associating it with an empty string, or some other convention.
Also consider something like
enum class ErrorCode {Error1 = 1, Error2};
where ErrorCode() represents success. The standard library std::errc uses this convention. In this case you would want to be able to serialize/deserialize
In
traits.h
, in the macroThorsAnvil_MakeEnum
, we haveThis looks to me like it will only work for enum types with consecutive values. That is, it will work for your test case,
but not for something like
Note that in the latter instance, the default initialized value
FloatFormat()
is a valid enum value even though, being 0, there is no name for it in the list, and the named values are not consecutive.Instead of generating an array of
# member
, I would suggest generating an array of{EnumName::member, # member}
pairs. ThengetValue
can search for the name and return the correspondingEnumName
. I think you also need a fallback if there is no name for the default initialized valueEnumName()
, perhaps associating it with an empty string, or some other convention.Also consider something like
where
ErrorCode()
represents success. The standard librarystd::errc
uses this convention. In this case you would want to be able to serialize/deserializeBest regards, Daniel