Home > Frameworks > boost::bimap


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:

  • left_based
  • right_based
  • set_of_relation<>
  • multiset_of_relation<>
  • unordered_set_of_relation<>
  • unordered_multiset_of_relation<>
  • list_of_relation
  • vector_of_relation
  • unconstrained_set_of_relation

I could easily see bimap as a powerful tool to hold in memory a set of relational data base tables.

Categories: Frameworks
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: