How to make reference variable to boost::bimap.left?

331 Views Asked by At

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;
2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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

paramIDStrings::left_map &paramIDStringsByID = paramIDStrings.left;