folly::get_default

get_default overloads

Synopses

Declared in <folly/container/MapUtil.h>

Given a map and a key, return the value corresponding to the key in the map, or a given default value if the key doesn't exist in the map.

template<
    typename Map,
    typename Key = Map::key_type>
Map::mapped_type
get_default(
    Map const& map,
    Key const& key);
» more...

Give a map and a key, return the value corresponding to the key in the map, or a given default value if the key doesn't exist in the map.

template<
    class Map,
    typename Key = Map::key_type,
    typename Func>
requires is_invocable_r_v<typename Map::mapped_type, Func>
Map::mapped_type
get_default(
    Map const& map,
    Key const& key,
    Func&& dflt);
» more...

Given a map and a key, return the value corresponding to the key in the map, or the given default value if the key doesn't exist in the map.

template<
    class Map,
    typename Key = Map::key_type,
    typename Value = Map::mapped_type>
requires !std::is_invocable_v<Value>
Map::mapped_type
get_default(
    Map const& map,
    Key const& key,
    Value&& dflt);
» more...

Given a map and a path of keys, return the value corresponding to the nested value, or a given default value if the path doesn't exist in the map. The default value is the last parameter, and is copied when returned.

template<
    class Map,
    class Key1,
    class Key2,
    class... KeysDefault>
requires sizeof...(KeysDefault) != 0
/* implementation-defined */::type
get_default(
    Map const& map,
    Key1 const& key1,
    Key2 const& key2,
    KeysDefault const&... keysDefault);
» more...

Return Value

  • The value if the key exists, or a value-initialized default.
  • The value if the key exists, or the default value otherwise.
  • The nested value, or the default value if the path doesn't exist.

Parameters

NameDescription
mapThe map to search.
keyThe key to look up.
dfltA functor invoked to produce the default value.
key1The first key in the path.
key2The second key in the path.
keysDefaultThe remaining keys followed by the default value.