Boost logo

Boost :

From: Frank Laub (frank.laub_at_[hidden])
Date: 2005-12-09 19:33:23


>
> This looks really nice, especially if you could get the _VALUES version.
> I'd very much like to see something like that in Boost.

I'm in the midst of completing this feature.. almost there! What do you
think a good name for it is? BOOST_ENUM_VALUES or BOOST_STRINGTABLE or
something else maybe?

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 reason I did this is because my preprocessor fu is not strong enough.
The problem is how to deal with the trailing comma at the end.. my hack is
to place another 'trailing' field to keep from having syntax errors.

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...

Ya, I could see the size being outside.. but because of my trailing comma
concern, thought I'd kill two birds with one stone.

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.

In all the actualy uses of this thing I've always needed an 'Invalid' field
which is specifically used for things like default ctors. I can see how some
users would rather add it themselves.. maybe they're worried about clashes.
Perhaps there is a way to make the enum type be more than just a class-type
(or a type with only static members on it). I was toying with an
instanciable enum type, but I haven't gotten too far with it.

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?

Ah, that was an older version, the current version should print the size at
the end, minus the Invalid. Good catch!

Thanks for all the comments!

-Frank


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk