mirror of
https://github.com/NixOS/nix.git
synced 2025-12-16 14:01:05 +01:00
Merge pull request #13763 from obsidiansystems/more-flexible-get
More flexible typing for `get` in `util.hh`
This commit is contained in:
commit
1ed3ae8a9d
1 changed files with 6 additions and 7 deletions
|
|
@ -196,8 +196,8 @@ std::pair<std::string_view, std::string_view> getLine(std::string_view s);
|
||||||
/**
|
/**
|
||||||
* Get a value for the specified key from an associate container.
|
* Get a value for the specified key from an associate container.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T, typename K>
|
||||||
const typename T::mapped_type * get(const T & map, const typename T::key_type & key)
|
const typename T::mapped_type * get(const T & map, K & key)
|
||||||
{
|
{
|
||||||
auto i = map.find(key);
|
auto i = map.find(key);
|
||||||
if (i == map.end())
|
if (i == map.end())
|
||||||
|
|
@ -205,8 +205,8 @@ const typename T::mapped_type * get(const T & map, const typename T::key_type &
|
||||||
return &i->second;
|
return &i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T, typename K>
|
||||||
typename T::mapped_type * get(T & map, const typename T::key_type & key)
|
typename T::mapped_type * get(T & map, K & key)
|
||||||
{
|
{
|
||||||
auto i = map.find(key);
|
auto i = map.find(key);
|
||||||
if (i == map.end())
|
if (i == map.end())
|
||||||
|
|
@ -221,9 +221,8 @@ typename T::mapped_type * get(T && map, const typename T::key_type & key) = dele
|
||||||
/**
|
/**
|
||||||
* Get a value for the specified key from an associate container, or a default value if the key isn't present.
|
* Get a value for the specified key from an associate container, or a default value if the key isn't present.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T, typename K>
|
||||||
const typename T::mapped_type &
|
const typename T::mapped_type & getOr(T & map, K & key, const typename T::mapped_type & defaultValue)
|
||||||
getOr(T & map, const typename T::key_type & key, const typename T::mapped_type & defaultValue)
|
|
||||||
{
|
{
|
||||||
auto i = map.find(key);
|
auto i = map.find(key);
|
||||||
if (i == map.end())
|
if (i == map.end())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue