-
Notifications
You must be signed in to change notification settings - Fork 0
BidiMap
Gautier Lefebvre edited this page Feb 13, 2018
·
2 revisions
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
.
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;
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;