diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 6af24555b..ca4ce98b8 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3863,7 +3863,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return it->template get::type>(); } - return default_value; + return std::forward(default_value); } JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); @@ -3877,11 +3877,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::is_usable_as_key_type::value > ... > string_t value(const KeyType& key, const char* default_value) const { -#ifdef JSON_HAS_CPP_17 - return value(key, std::string_view(default_value)); -#else return value(key, string_t(default_value)); -#endif } /*! diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 6958ece69..f6c004e5c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20953,7 +20953,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return it->template get::type>(); } - return default_value; + return std::forward(default_value); } JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); @@ -20967,11 +20967,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec detail::is_usable_as_key_type::value > ... > string_t value(const KeyType& key, const char* default_value) const { -#ifdef JSON_HAS_CPP_17 - return value(key, std::string_view(default_value)); -#else return value(key, string_t(default_value)); -#endif } /*!