Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
71830be0
Commit
71830be0
authored
Jun 10, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issue#1275
parent
28048d82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+25
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+25
-0
No files found.
include/nlohmann/json.hpp
View file @
71830be0
...
...
@@ -3788,6 +3788,31 @@ class basic_json
JSON_THROW
(
type_error
::
create
(
306
,
"cannot use value() with "
+
std
::
string
(
type_name
())));
}
/*!
@brief overload for a default value of type rvalue
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
template
<
class
ValueType
,
typename
std
::
enable_if
<
std
::
is_convertible
<
basic_json_t
,
detail
::
uncvref_t
<
ValueType
>
>::
value
and
not
std
::
is_same
<
value_t
,
ValueType
>::
value
,
int
>::
type
=
0
>
detail
::
uncvref_t
<
ValueType
>
value
(
const
typename
object_t
::
key_type
&
key
,
ValueType
&&
default_value
)
&&
{
// 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
std
::
move
(
it
->
template
get_ref
<
ValueType
&
>());
}
return
std
::
forward
<
ValueType
>
(
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*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
...
...
single_include/nlohmann/json.hpp
View file @
71830be0
...
...
@@ -19566,6 +19566,31 @@ class basic_json
JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name())));
}
/*!
@brief overload for a default value of type rvalue
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
template<class ValueType, typename std::enable_if<
std::is_convertible<basic_json_t, detail::uncvref_t<ValueType>>::value
and not std::is_same<value_t, ValueType>::value, int>::type = 0>
detail::uncvref_t<ValueType> value(const typename object_t::key_type& key, ValueType && default_value) &&
{
// 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 std::move(it->template get_ref<ValueType&>());
}
return std::forward<ValueType>(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*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment