fix the bug
This commit is contained in:
parent
e3e9ccfc02
commit
d13873482e
@ -3803,13 +3803,34 @@ class basic_json
|
|||||||
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, ValueType && default_value) const
|
||||||
|
{
|
||||||
|
// at only works for objects
|
||||||
|
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||||
|
{
|
||||||
|
// if key is found, return value and given default value otherwise
|
||||||
|
const auto it = find(key);
|
||||||
|
if (it != end())
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief overload for a default value of type const char*
|
@brief overload for a default value of type const char*
|
||||||
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
|
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
|
||||||
*/
|
*/
|
||||||
string_t value(const typename object_t::key_type& key, const char* default_value) const
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -3876,6 +3897,27 @@ class basic_json
|
|||||||
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class ValueType, typename std::enable_if<
|
||||||
|
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
|
||||||
|
ValueType value(const json_pointer& ptr, ValueType && default_value) const
|
||||||
|
{
|
||||||
|
// at only works for objects
|
||||||
|
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||||
|
{
|
||||||
|
// if pointer resolves a value, return it or use default value
|
||||||
|
JSON_TRY
|
||||||
|
{
|
||||||
|
return ptr.get_checked(this);
|
||||||
|
}
|
||||||
|
JSON_INTERNAL_CATCH (out_of_range&)
|
||||||
|
{
|
||||||
|
return std::move(default_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief overload for a default value of type const char*
|
@brief overload for a default value of type const char*
|
||||||
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
||||||
@ -3883,7 +3925,7 @@ class basic_json
|
|||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
string_t value(const json_pointer& ptr, const char* default_value) const
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@ -19733,13 +19733,34 @@ class basic_json
|
|||||||
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, ValueType && default_value) const
|
||||||
|
{
|
||||||
|
// at only works for objects
|
||||||
|
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||||
|
{
|
||||||
|
// if key is found, return value and given default value otherwise
|
||||||
|
const auto it = find(key);
|
||||||
|
if (it != end())
|
||||||
|
{
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief overload for a default value of type const char*
|
@brief overload for a default value of type const char*
|
||||||
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
|
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
|
||||||
*/
|
*/
|
||||||
string_t value(const typename object_t::key_type& key, const char* default_value) const
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -19806,6 +19827,27 @@ class basic_json
|
|||||||
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class ValueType, typename std::enable_if<
|
||||||
|
std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
|
||||||
|
ValueType value(const json_pointer& ptr, ValueType && default_value) const
|
||||||
|
{
|
||||||
|
// at only works for objects
|
||||||
|
if (JSON_HEDLEY_LIKELY(is_object()))
|
||||||
|
{
|
||||||
|
// if pointer resolves a value, return it or use default value
|
||||||
|
JSON_TRY
|
||||||
|
{
|
||||||
|
return ptr.get_checked(this);
|
||||||
|
}
|
||||||
|
JSON_INTERNAL_CATCH (out_of_range&)
|
||||||
|
{
|
||||||
|
return std::move(default_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief overload for a default value of type const char*
|
@brief overload for a default value of type const char*
|
||||||
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
@copydoc basic_json::value(const json_pointer&, ValueType) const
|
||||||
@ -19813,7 +19855,7 @@ class basic_json
|
|||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
string_t value(const json_pointer& ptr, const char* default_value) const
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user