I recently saw that boost has a bidirectional map implementation named bimap.
My initial STL map was using the following 2 types:
int
as the key typestd::weak_ptr<void>
as the value type (let's call itX
)
Scenario 1
To create a bimap with these types, the declaration would be something like
boost::bimap<int, boost::bimaps::set_of<X, std::owner_less<X>>>
since std::weak_ptr
needs an less operator (provided by std::owner_less
) and is linked to the type with boost::bimaps::set_of
to be usable(If I understood correctly).
Scenario 2
I want my int
type key from the map to point to multiple values of type X
.
For a standard map, changing the value type from X
to std::list<X>
would be ok as in:
std::map<int, std::list<X>>
How could the bidirectional map be defined (or what can be used) so that right map view would be interpreted as a map<X,int>
(flattening the lists of X
), while the right one still being a map<int,list<X>>
?