Boost :: bimap for listing

I am trying to create a simple bidirectional search engine for enumerations in C ++. My one-way search works fine ...

enum MyEnum
{ 
    One, 
    Two, 
    Three 
};

const boost::unordered_map<MyEnum,std::string> MyEnumMap = map_list_of
    (One, "One")
    (Two, "Two")
    (Three, "Three");

and then looking through

MyEnumMap.at(One)

This works, but only allows key-based searches. I would like to use a bidirectional search container, for example boost: bimap, to simplify the reverse search based on value as well as key. Map_list_of seems to be compatible with boost :: bimap.

Firstly, should I use map_list_of with boost :: bimap or do I need a different type? All cards will be base (Enum, string).

-, , const , ? , , typedef .. .

+5
1

list_of:

typedef boost::bimap< MyEnum, std::string > bm_type;
const bm_type MyEnumMap =
  boost::assign::list_of< bm_type::relation >
    ( One, "One" )
    ( Two, "Two" )
    ( Three, "Three" );

'' 'value_type'.

+12

All Articles