On Jun 8, 2015, at 21:27, Gavin Lambert
wrote: On 9/06/2015 13:16, Anton Bachin wrote:
(As an aside, it was quite a handy data structure. It was mainly intended for string-to-enum conversions but because of the way it was templated it could be abused to do string-to-member-pointer conversions as well, which enabled all sorts of interesting reflection scenarios.)
I am curious to know what this was, it sounds interesting.
It wasn't really all that interesting. It was just a "data table class" with some helper macros that let you define a static const structure private to a .cpp file (and initialised at compile time) to contain the string and value, plus a "lookup class" that was declared in the .h (as a static global) that was initialised with the address of the table. All the actual searching was done at runtime by the lookup class, with the table class basically just POD. <snip>
That’s useful to know, thank you. I’d like to make Better Enums the join (meet?) of good approaches, so your message was helpful both for the method and for the use cases. 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).