ROSE
0.11.96.11
|
Extends std::map with methods that return optional values.
#include <Map.h>
Public Types | |
typedef std::map< Key, T, Compare, Alloc > | map_type |
Public Member Functions | |
Map (const Compare &comp, const Alloc &alloc=Alloc()) | |
template<class InputIterator > | |
Map (InputIterator first, InputIterator last, const Compare &comp=Compare(), const Alloc &alloc=Alloc()) | |
Map (const Map &other) | |
boost::optional< T > | get (const Key &key) const |
Lookup and return a value or nothing. More... | |
bool | exists (const Key &key) const |
Convenience for determining if a key exists in this map. More... | |
const T & | get_one (const Key &key) const |
Look up one value or throw an exception. More... | |
T & | get_one (const Key &key) |
Look up one value or throw an exception. More... | |
const T & | get_value_or (const Key &key, const T &dflt) const |
Convenience for getting a value from an Option. More... | |
T & | get_value_or (const Key &key, T &dflt) |
Convenience for getting a value from an Option. More... | |
|
inline |
Lookup and return a value or nothing.
This is similar to the operator[] defined for std::map, but does not add a new pair to the map when the key does not exist. It returns a copy of the value that was found (if found). Here's an example of the usual way to use this:
|
inline |
Look up one value or throw an exception.
This is like get() except it can't handle the case where the map does not contain the requested key. It is unlike operator[] in that it doesn't add a new default-constructed value. The return value is a reference to the value stored in the map.
|
inline |
Look up one value or throw an exception.
This is like get() except it can't handle the case where the map does not contain the requested key. It is unlike operator[] in that it doesn't add a new default-constructed value. The return value is a reference to the value stored in the map.
|
inline |
Convenience for getting a value from an Option.
Since the "map.get(key).get_value_or(dflt)" idiom is so frequenct, a get_value_or() method is defined directly on the map, combining both arguments into a single method call.
|
inline |
Convenience for getting a value from an Option.
Since the "map.get(key).get_value_or(dflt)" idiom is so frequenct, a get_value_or() method is defined directly on the map, combining both arguments into a single method call.
|
inline |
Convenience for determining if a key exists in this map.
The STL map requires one to do a find() and compare the result to end(). Although that can be more efficient when the value for that key will be used (because one just dereferences the already-obtained iterator rather than searching again), it requires more code when all one wants to do is check for existence.