Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
eb0f8d73
Unverified
Commit
eb0f8d73
authored
May 03, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
👌
apply review comments
parent
12c0bc4c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
33 deletions
+33
-33
contains.md
doc/mkdocs/docs/api/basic_json/contains.md
+1
-1
count.md
doc/mkdocs/docs/api/basic_json/count.md
+1
-1
find.md
doc/mkdocs/docs/api/basic_json/find.md
+2
-2
value.md
doc/mkdocs/docs/api/basic_json/value.md
+3
-3
json.hpp
include/nlohmann/json.hpp
+13
-13
json.hpp
single_include/nlohmann/json.hpp
+13
-13
No files found.
doc/mkdocs/docs/api/basic_json/contains.md
View file @
eb0f8d73
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
```
cpp
```
cpp
template
<
typename
KeyT
>
template
<
typename
KeyT
>
bool
contains
(
KeyT
&
&
key
)
const
;
bool
contains
(
const
KeyT
&
key
)
const
;
```
```
Check whether an element exists in a JSON object with key equivalent to
`key`
. If the element is not found or the JSON
Check whether an element exists in a JSON object with key equivalent to
`key`
. If the element is not found or the JSON
...
...
doc/mkdocs/docs/api/basic_json/count.md
View file @
eb0f8d73
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
```
cpp
```
cpp
template
<
typename
KeyT
>
template
<
typename
KeyT
>
size_type
count
(
KeyT
&
&
key
)
const
;
size_type
count
(
const
KeyT
&
key
)
const
;
```
```
Returns the number of elements with key
`key`
. If
`ObjectType`
is the default
`std::map`
type, the return value will
Returns the number of elements with key
`key`
. If
`ObjectType`
is the default
`std::map`
type, the return value will
...
...
doc/mkdocs/docs/api/basic_json/find.md
View file @
eb0f8d73
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
```
cpp
```
cpp
template
<
typename
KeyT
>
template
<
typename
KeyT
>
iterator
find
(
KeyT
&
&
key
);
iterator
find
(
const
KeyT
&
key
);
template
<
typename
KeyT
>
template
<
typename
KeyT
>
const_iterator
find
(
KeyT
&
&
key
)
const
const_iterator
find
(
const
KeyT
&
key
)
const
```
```
Finds an element in a JSON object with key equivalent to
`key`
. If the element is not found or the JSON value is not an
Finds an element in a JSON object with key equivalent to
`key`
. If the element is not found or the JSON value is not an
...
...
doc/mkdocs/docs/api/basic_json/value.md
View file @
eb0f8d73
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
```
cpp
```
cpp
// (1)
// (1)
template
<
class
KeyType
,
class
ValueType
>
template
<
class
KeyType
,
class
ValueType
>
ValueType
value
(
KeyType
&
&
key
,
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
;
ValueType
&
&
default_value
)
const
;
// (2)
// (2)
template
<
class
ValueType
>
template
<
class
ValueType
>
ValueType
value
(
const
json_pointer
&
ptr
,
ValueType
value
(
const
json_pointer
&
ptr
,
const
ValueType
&
default_value
)
const
;
ValueType
&
&
default_value
)
const
;
```
```
1.
Returns either a copy of an object's element at the specified key
`key`
or a given default value if no element with
1.
Returns either a copy of an object's element at the specified key
`key`
or a given default value if no element with
...
...
include/nlohmann/json.hpp
View file @
eb0f8d73
...
@@ -3834,13 +3834,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3834,13 +3834,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
KeyType
&&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
const
KeyType
&
key
,
ValueType
&
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
{
// if key is found, return value and given default value otherwise
// if key is found, return value and given default value otherwise
const
auto
it
=
find
(
std
::
forward
<
KeyType
>
(
key
)
);
const
auto
it
=
find
(
key
);
if
(
it
!=
end
())
if
(
it
!=
end
())
{
{
return
it
->
template
get
<
ValueType
>
();
return
it
->
template
get
<
ValueType
>
();
...
@@ -3908,7 +3908,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3908,7 +3908,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
ValueType
,
typename
std
::
enable_if
<
template
<
class
ValueType
,
typename
std
::
enable_if
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
,
int
>::
type
=
0
>
detail
::
is_getable
<
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
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -4380,13 +4380,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4380,13 +4380,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
KeyT
&
&
key
)
iterator
find
(
const
KeyT
&
key
)
{
{
auto
result
=
end
();
auto
result
=
end
();
if
(
is_object
())
if
(
is_object
())
{
{
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
key
);
}
}
return
result
;
return
result
;
...
@@ -4394,17 +4394,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4394,17 +4394,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief find an element in a JSON object
@brief find an element in a JSON object
@copydoc find(
KeyT&
&)
@copydoc find(
const KeyT
&)
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
KeyT
&
&
key
)
const
const_iterator
find
(
const
KeyT
&
key
)
const
{
{
auto
result
=
cend
();
auto
result
=
cend
();
if
(
is_object
())
if
(
is_object
())
{
{
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
key
);
}
}
return
result
;
return
result
;
...
@@ -4433,10 +4433,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4433,10 +4433,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
KeyT
&
&
key
)
const
size_type
count
(
const
KeyT
&
key
)
const
{
{
// return 0 for all nonobject types
// return 0 for all nonobject types
return
is_object
()
?
m_value
.
object
->
count
(
std
::
forward
<
KeyT
>
(
key
)
)
:
0
;
return
is_object
()
?
m_value
.
object
->
count
(
key
)
:
0
;
}
}
/*!
/*!
...
@@ -4459,16 +4459,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4459,16 +4459,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@liveexample{The following code shows an example for `contains()`.,contains}
@liveexample{The following code shows an example for `contains()`.,contains}
@sa see @ref find(
KeyT&
&) -- returns an iterator to an object element
@sa see @ref find(
const KeyT
&) -- returns an iterator to an object element
@sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer
@sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer
@since version 3.6.0
@since version 3.6.0
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
bool
contains
(
KeyT
&
&
key
)
const
bool
contains
(
const
KeyT
&
key
)
const
{
{
return
is_object
()
&&
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
)
!=
m_value
.
object
->
end
();
return
is_object
()
&&
m_value
.
object
->
find
(
key
)
!=
m_value
.
object
->
end
();
}
}
/*!
/*!
...
...
single_include/nlohmann/json.hpp
View file @
eb0f8d73
...
@@ -20867,13 +20867,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20867,13 +20867,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
KeyType
&&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
const
KeyType
&
key
,
ValueType
&
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
{
// if key is found, return value and given default value otherwise
// if key is found, return value and given default value otherwise
const
auto
it
=
find
(
std
::
forward
<
KeyType
>
(
key
)
);
const
auto
it
=
find
(
key
);
if
(
it
!=
end
())
if
(
it
!=
end
())
{
{
return
it
->
template
get
<
ValueType
>
();
return
it
->
template
get
<
ValueType
>
();
...
@@ -20941,7 +20941,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20941,7 +20941,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
ValueType
,
typename
std
::
enable_if
<
template
<
class
ValueType
,
typename
std
::
enable_if
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
,
int
>::
type
=
0
>
detail
::
is_getable
<
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
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -21413,13 +21413,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21413,13 +21413,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
KeyT
&
&
key
)
iterator
find
(
const
KeyT
&
key
)
{
{
auto
result
=
end
();
auto
result
=
end
();
if
(
is_object
())
if
(
is_object
())
{
{
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
key
);
}
}
return
result
;
return
result
;
...
@@ -21427,17 +21427,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21427,17 +21427,17 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief find an element in a JSON object
@brief find an element in a JSON object
@copydoc find(
KeyT&
&)
@copydoc find(
const KeyT
&)
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
KeyT
&
&
key
)
const
const_iterator
find
(
const
KeyT
&
key
)
const
{
{
auto
result
=
cend
();
auto
result
=
cend
();
if
(
is_object
())
if
(
is_object
())
{
{
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
result
.
m_it
.
object_iterator
=
m_value
.
object
->
find
(
key
);
}
}
return
result
;
return
result
;
...
@@ -21466,10 +21466,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21466,10 +21466,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
KeyT
&
&
key
)
const
size_type
count
(
const
KeyT
&
key
)
const
{
{
// return 0 for all nonobject types
// return 0 for all nonobject types
return
is_object
()
?
m_value
.
object
->
count
(
std
::
forward
<
KeyT
>
(
key
)
)
:
0
;
return
is_object
()
?
m_value
.
object
->
count
(
key
)
:
0
;
}
}
/*!
/*!
...
@@ -21492,16 +21492,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21492,16 +21492,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@liveexample{The following code shows an example for `contains()`.,contains}
@liveexample{The following code shows an example for `contains()`.,contains}
@sa see @ref find(
KeyT&
&) -- returns an iterator to an object element
@sa see @ref find(
const KeyT
&) -- returns an iterator to an object element
@sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer
@sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer
@since version 3.6.0
@since version 3.6.0
*/
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
bool
contains
(
KeyT
&
&
key
)
const
bool
contains
(
const
KeyT
&
key
)
const
{
{
return
is_object
()
&&
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
)
!=
m_value
.
object
->
end
();
return
is_object
()
&&
m_value
.
object
->
find
(
key
)
!=
m_value
.
object
->
end
();
}
}
/*!
/*!
...
...
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