
Frank Laub wrote:
BOOST_ENUM(Boolean, (False) (True) )
This looks really nice, especially if you could get the _VALUES version. I'd very much like to see something like that in Boost.
to:
class Boolean_base { public: enum type { False, True, size = 2, Invalid = -1 };
protected: typedef boost::array<const char*, (size)+1> array_type; static const array_type& storage() { static const array_type names = { "False", "True", "2" }; return names; } }; typedef safe_enum<Boolean_base> Boolean;
A few small remarks: I doubt if the storage array needs to be 'size+1' large. The last element of the size itself doesn't need to be stringized. The size value of the enum type itself can be moved outside to be a 'const size_t size = 2;'. I'm not sure that it really matters, I just think it's more elegant. But of course you can disagree... I also think the addition of the 'Invalid' value is not needed. If the enum::type would have been default constructed to 'Invalid', then there might be justification for this. But AFAICS, this is not the case, so IMO it's better removed. The user can always add it himself. BTW, the example in your first message showed a 'foreach(..., Level::names)' printing all values including "Invalid", not including the size. Accroding to the implemenation I see here, this seems to be impossible. Or did I miss anything? Yuval