The boost::bimap framework offers a bi-directional version of the STL map container. That is, both members of its pair elements can be used as a key to access its counterpart.
The way it works is by, internally, pairing two stl::map containers each matching the other one. The two maps are referred to as left and right. If for instance our templated types are X,Y, the left map uses X as the Key, and Y as the value. Inversely, the right map uses Y as the key and X as the value.
In both cases, the element used as key is const. As bimap does a little internal work to keep both maps in sync, it prevents the keys from left & right to be changed.
Here’s an overview of bimap:
There is many options to control the relationship between X and Y:
I could easily see bimap as a powerful tool to hold in memory a set of relational data base tables.