Map and Unordered Map#
Both of these classes inherit from the std::map
and std::unordered_map
classes respectively, implementing a
few additional features to make them easier to use and more versatile.
For the full documentation on the std::map
and std::unordered_map
classes, see
the map (C++ reference)
and unordered map (C++ reference) pages.
-
namespace librapid
-
template<typename Key, typename Value>
class Map : public std::map<Key, Value> - #include <map.hpp>
Public Functions
-
inline bool contains(const Key &key) const
Check if a key exists in the map.
- Parameters
key – Key to search for
- Returns
Boolean
-
inline bool contains(const Key &key, Value &value) const
Check if a key exists in the map and, if it does, set
value
to the value of the key. The function returns true if the key exists, false otherwise. (If the function returns false,value
will not be modified/initialized, so make sure you check the return value!)- Parameters
key – Key to search for
value – Value of the key, if it exists (output)
- Returns
True if the key exists, false otherwise
-
inline auto get(const Key &key) const
Get the value of a key.
- Parameters
key – Key to search for
- Returns
Value of the key
-
inline auto get(const Key &key, const Value &defaultValue) const
Get the value of a key, or a default value if the key does not exist.
- Parameters
key – Key to search for
defaultValue – Default value to return if the key does not exist
- Returns
Value of the key, or
defaultValue
if the key does not exist
-
inline std::string str(const std::string &keyFormat = "{}", const std::string &valueFormat = "{}") const
-
inline bool contains(const Key &key) const
-
template<typename Key, typename Value>
class UnorderedMap : public std::unordered_map<Key, Value> - #include <map.hpp>
Public Functions
-
inline bool contains(const Key &key) const
Check if a key exists in the map.
- Parameters
key – Key to search for
- Returns
Boolean
-
inline bool contains(const Key &key, Value &value) const
Check if a key exists in the map and, if it does, set
value
to the value of the key. The function returns true if the key exists, false otherwise. (If the function returns false,value
will not be modified/initialized, so make sure you check the return value!)- Parameters
key – Key to search for
value – Value of the key, if it exists (output)
- Returns
True if the key exists, false otherwise
-
inline auto get(const Key &key) const
Get the value of a key.
- Parameters
key – Key to search for
- Returns
Value of the key
-
inline auto get(const Key &key, const Value &defaultValue) const
Get the value of a key, or a default value if the key does not exist.
- Parameters
key – Key to search for
defaultValue – Default value to return if the key does not exist
- Returns
Value of the key, or
defaultValue
if the key does not exist
-
inline std::string str(const std::string &keyFormat = "{}", const std::string &valueFormat = "{}") const
-
inline bool contains(const Key &key) const
-
template<typename Key, typename Value>