0

I'm using boost::bimap to map integers to strings:

typedef boost::bimap<int, std::string> ParamIDStrings;
typedef ParamIDStrings::value_type id_pair;
extern const ParamIDStrings paramIDStrings;

I'm trying to create reference variables so I can write code like:

paramIDStringsByID.at(5);
// Instead of having to remember which side is which:
paramIDStrings.left.at(5);

But I'm having a hard time interpreting the Boost documentation, to understand of what type bimap::left is.

I tried:

// Compiler throws error: invalid use of template-name 'boost::bimaps::bimap' without an argument list
boost::bimaps::bimap::left &paramIDStringsByID = paramIDStrings.left;

// Compiler throws error: 'paramIDStrings' does not name a type
paramIDStrings::left_map &paramIDStringsByID = paramIDStrings.left;

// Compiler throws error: invalid initialization of reference of type boost::bimaps::bimap<int, std::__cxx11::basic_string<char> >::left_map
boost::bimaps::bimap<int,std::string>::left_map &cParamIDStringsByID = cParamIDStrings.left;
DBedrenko
  • 4,871
  • 4
  • 38
  • 73
  • 1
    Have you tried `auto &` and not care? – nwp Jun 07 '16 at 08:16
  • @nwp Whoa, thank you. Now I know what `auto` is useful for. If you make an answer I will accept it. Still, would be good to know what the actual type is, if only to learn how the heck to read these confusing Boost docs. – DBedrenko Jun 07 '16 at 08:25
  • 2
    how about `boost::bimaps::bimap::left_map & lmap` ? – Hummingbird Jun 07 '16 at 08:39
  • @DevanshMohanKaushik I tried it but it didn't work (I added the error message to my question). – DBedrenko Jun 07 '16 at 08:51
  • 2
    that's strange. Because `boost::bimap< int,std::string > mymap;` `boost::bimaps::bimap::left_map & lmap= mymap.left;` works fine for me. – Hummingbird Jun 07 '16 at 09:12

2 Answers2

2

You can use auto & to let the compiler do the work for you.
If you want to know the type that gets deduced you can use one of the tricks from here to make the compiler tell you.

Community
  • 1
  • 1
nwp
  • 9,623
  • 5
  • 38
  • 68
0

boost/bimap/bimap.hpp has a typedef for this: left_map and right_map. So you can do:

paramIDStrings::left_map &paramIDStringsByID = paramIDStrings.left;
DBedrenko
  • 4,871
  • 4
  • 38
  • 73