Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Bimap and Boost

Bimap and MultiIndex
Boost Libraries that work well with Boost.Bimap
Introduction
Boost.Serialization
Boost.Assign
Boost.Hash
Boost.Lambda
Boost.Range
Boost.Foreach
Boost.Typeof
Boost.Xpressive
Boost.Property_map
Dependencies

MISC - Multi-Index Specialized Containers

Let's be generic, construct frameworks, describe the world in an unified way...

No!, it is better to be specialized, design easy-to-use components, offer plug-and-play objects...

Why not take advantage of the best of both worlds?

miBimapFramework

With Boost.Bimap, you can build associative containers in which both types can be used as key. There is a library in Boost that already allows the creation of this kind of container: Boost.MultiIndex. It offers great flexibility and lets you construct almost any container that you could dream of. The framework is very clean. You might want to read this library's tutorial to learn about the power that has been achieved.

But generality comes at a price: the interface that results might not be the best for every specialization. People may end up wrapping a B.MI container in its own class every time they want to use it as a bidirectional map. Boost.Bimap takes advantage of the narrower scope to produce a better interface for bidirectional maps [2]. There is no learning curve if you know how to use standard containers. Great effort was put into mapping the naming scheme of the STL to Boost.Bimap. The library is designed to match the common STL containers.

Boost.MultiIndex is, in fact, the core of the bimap container.

However, Boost.Bimap do not aim to tackle every problem with two indexed types. There exist some problems that are better modelled with Boost.MultiIndex.

Problem I - An employee register

Store an ID and a name for an employee, with fast search on each member.

This type of problem is better modelled as a database table, and Boost.MultiIndex is the preferred choice. It is possible that other data will need to be indexed later.

Problem II - A partners container

Store the names of couples and be able to get the name of a person's partner.

This problem is better modelled as a collection of relations, and Boost.Bimap fits nicely here.

You can also read Additional Information for more information about the relation of this two libraries.



[2] In the same fashion, Boost.MRU will allow the creation of most recent updated aware containers, hiding the complexity of Boost.MultiIndex.


PrevUpHomeNext