Skip to content
Gautier Lefebvre edited this page Feb 13, 2018 · 2 revisions

BidiMap

A BidiMap is a bidirectional std::map, meaning that you can get the value from the key (as a normal std::map), or get the key from the value.

In order to do that, you must make sure that every key and every value are unique within the fwk::BidiMap.

Insert a new value

To insert a new value, you cannot use the underlying maps directly. You must use the fwk::BidiMap::insert method, this way:

fwk::BidiMap<int, const std::string> bidimap;

bidimap.insert(5, "foo");

// bidimap.key.at(5) == "foo";
// bidmap.value.at("foo") == 5;

Remove a value

In the same logic, you must use the fwk::BidiMap::erase method to remove a value. To remove a value you must use the key.

bidimap.erase(5);

// bidimap.value.at("foo") now throws std::out_of_range;