c++boosttypesboost-bimap

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


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;

Solution

  • 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.