#include <cassert>
#include <type_traits>
#include <unordered_map>
|
| template<class Map , class Key , class Value = typename Map::mapped_type> |
| Value | valueOr (const Map &map, const Key &key, const std::type_identity_t< Value > &def=Value()) |
| |
| template<class Map , class Key > |
| auto * | valuePtr (Map &&map, const Key &key) |
| |
| template<class Key , class Value > |
| std::unordered_map< Value, Key > | inverted (const std::unordered_map< Key, Value > &map) |
| |
◆ inverted()
template<class Key , class Value >
| std::unordered_map< Value, Key > inverted |
( |
const std::unordered_map< Key, Value > & |
map | ) |
|
Inverts an unordered map, creating a map from values into keys.
The values must be unique, otherwise the function will assert.
- Parameters
-
- Returns
- Inverted map.
◆ valueOr()
template<class Map , class Key , class Value = typename Map::mapped_type>
| Value valueOr |
( |
const Map & |
map, |
|
|
const Key & |
key, |
|
|
const std::type_identity_t< Value > & |
def = Value() |
|
) |
| |
Convenient map accessor that returns either the value stored in a map, or default value if the key doesn't exist.
- Parameters
-
| map | Map to get value from. |
| key | Key to look up value for. |
| def | Default value to return if the key is not in the map. |
- Returns
- Value for the provided key, or
def if the key was not found in the map.
◆ valuePtr()
template<class Map , class Key >
| auto * valuePtr |
( |
Map && |
map, |
|
|
const Key & |
key |
|
) |
| |
Convenient map accessor that returns either the pointer to the value stored in a map, or nullptr if the key doesn't exist.
- Parameters
-
| map | Map to get value from. |
| key | Key to look up value for. |
- Returns
- Pointer to the value for the provided key, or
nullptr if the key was not found in the map.