Skip to content

Commit 39be72a

Browse files
committed
fix utils: fix initialization of default values in FindOrDefault
1 parent 8d7fb78 commit 39be72a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

universal/include/userver/utils/algo.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ auto* FindOrNullptr(Container& container, const Key& key) {
5757
template <typename Container, typename Key, typename Default>
5858
auto FindOrDefault(Container& container, const Key& key, Default&& def) {
5959
const auto* ptr = USERVER_NAMESPACE::utils::FindOrNullptr(container, key);
60-
return (ptr ? *ptr : decltype(*ptr){std::forward<Default>(def)});
60+
using R = std::remove_cvref_t<decltype(*ptr)>;
61+
return (ptr ? *ptr : R(std::forward<Default>(def)));
6162
}
6263

6364
/// @brief Returns default value if no key in associative container, otherwise
6465
/// returns a copy of the stored value.
6566
template <typename Container, typename Key>
6667
auto FindOrDefault(Container& container, const Key& key) {
6768
const auto* ptr = USERVER_NAMESPACE::utils::FindOrNullptr(container, key);
68-
return (ptr ? *ptr : decltype(*ptr){});
69+
using R = std::remove_cvref_t<decltype(*ptr)>;
70+
return (ptr ? *ptr : R());
6971
}
7072

7173
/// @brief Returns std::nullopt if no key in associative container, otherwise

0 commit comments

Comments
 (0)