Does C++ have anything which behaves like std::map<T1, T2>
, but permitting not only looking for a T1
value to find its associated T2
value, but also to look for a particular T2
value to find its associated T1
value? (Which would mean values on both sides need to be unique.)
boost::bimap
is a data structure that behaves exactly the way you describe.
boost::bimap<T1,T2>::left
provides an interface that closely matches std::map<T1,T2>
, including all T1
-based lookupboost::bimap<T1,T2>::right
provides an interface that closely matches std::map<T2,T1>
, including all T2
-based lookupconst
. You can add and remove, but you can not modify in-place.