Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue#1275 #2181

Merged
merged 6 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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())));
Expand All @@ -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)));
}

/*!
Expand Down Expand Up @@ -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()))
Expand All @@ -3854,7 +3854,7 @@ class basic_json
}
JSON_INTERNAL_CATCH (out_of_range&)
{
return default_value;
return std::move(default_value);
}
}

Expand All @@ -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)));
}

/*!
Expand Down
12 changes: 6 additions & 6 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19548,7 +19548,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()))
Expand All @@ -19560,7 +19560,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())));
Expand All @@ -19572,7 +19572,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)));
}

/*!
Expand Down Expand Up @@ -19620,7 +19620,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()))
Expand All @@ -19632,7 +19632,7 @@ class basic_json
}
JSON_INTERNAL_CATCH (out_of_range&)
{
return default_value;
return std::move(default_value);
}
}

Expand All @@ -19646,7 +19646,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)));
}

/*!
Expand Down