Boost logo

Boost :

Subject: Re: [boost] Attn metaprogrammers! [Better Enums] More complete release - feedback requested
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2015-06-09 00:30:00


On 9/06/2015 14:53, Anton Bachin wrote:
> I’ve been thinking about the serialization scenario, in particular. I don’t know
> the full range of what you needed, but would something like the ability to alias
> constants to each other, and iterate over unique values only, have been
> sufficient? For example, a declaration like
>
> …OldName, MoreNames, NewName = OldName, …
>
> where OldName is for compatibility, and NewName is what you intend to use in
> your code. Converting the string "OldName" results in the same numeric value as
> NewName.
>
> When iterated over as values, the value of OldName/NewName would get visited
> only once. Also, when converting to string, there could be some convention such
> as the first name declared is the preferred one (actually the opposite of what I
> wrote above).

Yeah, that's essentially how my one worked. You could list the same
value multiple times with different strings, and when looking up by name
both the old and the new names would resolve to the same value, and when
looking up by value the first matching one listed in the table would be
the string returned.

I did have an enumeration feature but I don't recall if I made it smart
enough to avoid listing "duplicates". I don't think it came up all that
often in my particular use case.

The other interesting thing that you could do though was to have
separate tables for separate contexts. So for example with the same
actual enum, you could use one string table when reading/writing JSON
and a different table when reading/writing XML -- or one string for
internal use and another string for user display. That sort of thing.
(Although there are better ways to handle the latter, especially once
you start considering multiple languages.)


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