Subject: Re: [boost] Is there interest in a library for string-convertible enums?
From: Felix Uhl (felix.uhl_at_[hidden])
Date: 2014-10-28 19:18:33
On 28/10/2014, Rob Stewart wrote:
>That sounds interesting. Ease of use and compilation overhead are concerns, of course.
Iâll answer your ease of use concern with example code for definition
of the enum class Zott:
And now for the mentioned âflagâ values:
Seems easy enough. The second one could be shortened to another macro,
of course. Arbitrary values have a bit strange syntax, though:
> BOOST_ADCANCED_ENUM_ARBITRARY(4, 8, 6, 20),
Iâll see what I can do about that.
Conversions to and from string are done via static_cast (not sure
if thatâs the ideal solution), in- and output work naturally like this:
>Zott myZott = Zott:one;
>std::cin >> myZott; //if input is not convertible, no changes are made
>std::cout << myZott;
I think that's as easy as it can get :)
Compilation overhead indeed needs to be considered.
>What about enum classes?
My mistake, with ânamed enumsâ I meant âenum classesâ, but now that
you say it, I should try to implement string convertible
regular enums as well.
Thank you for your feedback!
Von: Rob Stewart
Gesendet: âDienstagâ, â28â. âOktoberâ â2014 â22â:â23
On October 28, 2014 7:09:35 AM EDT, Felix Uhl <felix.uhl_at_[hidden]> wrote:
>So far, the only way to convert an enumeration value to a string is a
>lot of boilerplate code consisting of switch case statements for every
>single possible value of the enum.
As Niall noted, most of us have done that before.
>Iâve written a small header-only library that uses Boost.Preprocessor
>and templates to ease the definition of named enumerations that are
>convertible to and from strings.
That sounds interesting. Ease of use and compilation overhead are concerns, of course.
>Currently, I am documenting the first version of the library to make it
>available on the Boost Library Incubator website,
I can hear Robert yelling, "Yes!"
> but I wanted to get
>some initial feedback from the developers mailing list, too. I would be
>glad to extend the library to a general extension of enumeration
>behaviour, like changing the generation of underlying values from a
>continuous increment to a continuous shift left by one, effectively
>making the underlying values binary flags.
That would certainly be useful.
What about enum classes?
(Sent from my portable computation engine)
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk