Merge pull request #2181 from dota17/issue#1275

Fix issue#1275
This commit is contained in:
Niels Lohmann 2020-06-23 09:23:03 +02:00 committed by GitHub
commit 8575fdf9ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View file

@ -3770,7 +3770,7 @@ class basic_json
template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value
and not std::is_same<value_t, ValueType>::value, int>::type = 0>
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
ValueType value(const typename object_t::key_type& key, ValueType && default_value) const
{
// at only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
@ -3782,7 +3782,7 @@ class basic_json
return *it;
}
return default_value;
return std::move(default_value);
}
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
@ -3794,7 +3794,7 @@ class basic_json
*/
string_t value(const typename object_t::key_type& key, const char* default_value) const
{
return value(key, string_t(default_value));
return value(key, std::move(string_t(default_value)));
}
/*!
@ -3842,7 +3842,7 @@ class basic_json
*/
template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
ValueType value(const json_pointer& ptr, const ValueType& default_value) const
ValueType value(const json_pointer& ptr, ValueType && default_value) const
{
// at only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
@ -3854,7 +3854,7 @@ class basic_json
}
JSON_INTERNAL_CATCH (out_of_range&)
{
return default_value;
return std::move(default_value);
}
}
@ -3868,7 +3868,7 @@ class basic_json
JSON_HEDLEY_NON_NULL(3)
string_t value(const json_pointer& ptr, const char* default_value) const
{
return value(ptr, string_t(default_value));
return value(ptr, std::move(string_t(default_value)));
}
/*!

View file

@ -19575,7 +19575,7 @@ class basic_json
template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value
and not std::is_same<value_t, ValueType>::value, int>::type = 0>
ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
ValueType value(const typename object_t::key_type& key, ValueType && default_value) const
{
// at only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
@ -19587,7 +19587,7 @@ class basic_json
return *it;
}
return default_value;
return std::move(default_value);
}
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
@ -19599,7 +19599,7 @@ class basic_json
*/
string_t value(const typename object_t::key_type& key, const char* default_value) const
{
return value(key, string_t(default_value));
return value(key, std::move(string_t(default_value)));
}
/*!
@ -19647,7 +19647,7 @@ class basic_json
*/
template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
ValueType value(const json_pointer& ptr, const ValueType& default_value) const
ValueType value(const json_pointer& ptr, ValueType && default_value) const
{
// at only works for objects
if (JSON_HEDLEY_LIKELY(is_object()))
@ -19659,7 +19659,7 @@ class basic_json
}
JSON_INTERNAL_CATCH (out_of_range&)
{
return default_value;
return std::move(default_value);
}
}
@ -19673,7 +19673,7 @@ class basic_json
JSON_HEDLEY_NON_NULL(3)
string_t value(const json_pointer& ptr, const char* default_value) const
{
return value(ptr, string_t(default_value));
return value(ptr, std::move(string_t(default_value)));
}
/*!