diff --git a/src/libutil/include/nix/util/util.hh b/src/libutil/include/nix/util/util.hh index 2361bf2e7..37d14d4fb 100644 --- a/src/libutil/include/nix/util/util.hh +++ b/src/libutil/include/nix/util/util.hh @@ -223,18 +223,18 @@ std::pair getLine(std::string_view s); /** * Get a value for the specified key from an associate container. */ -template -const typename T::mapped_type * get(const T & map, const typename T::key_type & key) +template +const typename T::mapped_type * get(const T & map, K && key) { - auto i = map.find(key); + auto i = map.find(std::forward(key)); if (i == map.end()) return nullptr; return &i->second; } -template -typename T::mapped_type * get(T & map, const typename T::key_type & key) +template +typename T::mapped_type * get(T & map, K && key) { - auto i = map.find(key); + auto i = map.find(std::forward(key)); if (i == map.end()) return nullptr; return &i->second; } @@ -242,12 +242,12 @@ typename T::mapped_type * get(T & map, const typename T::key_type & key) /** * Get a value for the specified key from an associate container, or a default value if the key isn't present. */ -template +template const typename T::mapped_type & getOr(T & map, - const typename T::key_type & key, + K && key, const typename T::mapped_type & defaultValue) { - auto i = map.find(key); + auto i = map.find(std::forward(key)); if (i == map.end()) return defaultValue; return i->second; }