Boost logo

Boost :

Subject: Re: [boost] enum / string translation
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-07-22 07:52:47

Zachary Turner a écrit :
> I wrote some code to perform both compile-time and runtime translation
> between enums and their corresponding string values. The only
> direction that isn't possible is string->enum at compile time.
> Is there any interest in this? You can use it as follows:
> typedef enum { ValueA1, ValueA2 } EnumA;
> typedef enum { ValueB1, ValueB2 } EnumB;
> BEGIN_ENUM_MAP(EnumA, a_map)
> ENUM_MAP(ValueA1) //maps ValueA1 to the string "ValueA1",
> provides both compile-time and run-time lookups.
> ENUM_MAP_NAME(ValueA2, "custom name") //maps ValueA2 to the
> string "custom name", provides both compile-time and run-time lookups
> BEGIN_ENUM_MAP(EnumB, b_map)
> ENUM_MAP(ValueB1)
> ENUM_MAP(ValueB2)

So that means I'll have a copy of the runtime map in every translation unit?

Boost list run by bdawes at, gregod at, cpdaniel at, john at