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
ea4891fb
Unverified
Commit
ea4891fb
authored
Mar 31, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
👌
implement some review comments
parent
02b36e92
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
24 deletions
+12
-24
erase.md
doc/mkdocs/docs/api/basic_json/erase.md
+1
-1
value.md
doc/mkdocs/docs/api/basic_json/value.md
+1
-1
json.hpp
include/nlohmann/json.hpp
+5
-11
json.hpp
single_include/nlohmann/json.hpp
+5
-11
No files found.
doc/mkdocs/docs/api/basic_json/erase.md
View file @
ea4891fb
...
...
@@ -11,7 +11,7 @@ const_iterator erase(const_iterator first, const_iterator last);
// (3)
template
<
typename
KeyT
>
size_type
erase
(
KeyT
&
&
key
);
size_type
erase
(
const
KeyT
&
key
);
// (4)
void
erase
(
const
size_type
idx
);
...
...
doc/mkdocs/docs/api/basic_json/value.md
View file @
ea4891fb
...
...
@@ -3,7 +3,7 @@
```
cpp
// (1)
template
<
class
KeyType
,
class
ValueType
>
ValueType
value
(
const
KeyType
&
key
,
ValueType
value
(
KeyType
&
&
key
,
const
ValueType
&
default_value
)
const
;
// (2)
...
...
include/nlohmann/json.hpp
View file @
ea4891fb
...
...
@@ -3694,13 +3694,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
it
=
m_value
.
object
->
find
(
key
);
if
(
it
!=
m_value
.
object
->
end
())
{
return
it
->
second
;
}
auto
result
=
m_value
.
object
->
emplace
(
key
,
nullptr
);
auto
result
=
m_value
.
object
->
emplace
(
std
::
forward
<
KeyT
>
(
key
),
nullptr
);
return
set_parent
(
result
.
first
->
second
);
}
...
...
@@ -3809,13 +3803,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
KeyType
&
&
key
,
const
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
);
const
auto
it
=
find
(
std
::
forward
<
KeyType
>
(
key
)
);
if
(
it
!=
end
())
{
return
it
->
template
get
<
ValueType
>
();
...
...
@@ -4259,7 +4253,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
erase
(
KeyT
&
&
key
)
size_type
erase
(
const
KeyT
&
key
)
{
// this erase only works for objects
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
...
...
@@ -4267,7 +4261,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
const
auto
it
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
const
auto
it
=
m_value
.
object
->
find
(
key
);
if
(
it
!=
m_value
.
object
->
end
())
{
m_value
.
object
->
erase
(
it
);
...
...
single_include/nlohmann/json.hpp
View file @
ea4891fb
...
...
@@ -20597,13 +20597,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
it
=
m_value
.
object
->
find
(
key
);
if
(
it
!=
m_value
.
object
->
end
())
{
return
it
->
second
;
}
auto
result
=
m_value
.
object
->
emplace
(
key
,
nullptr
);
auto
result
=
m_value
.
object
->
emplace
(
std
::
forward
<
KeyT
>
(
key
),
nullptr
);
return
set_parent
(
result
.
first
->
second
);
}
...
...
@@ -20712,13 +20706,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyType
,
class
ValueType
,
typename
detail
::
enable_if_t
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
KeyType
&
&
key
,
const
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
);
const
auto
it
=
find
(
std
::
forward
<
KeyType
>
(
key
)
);
if
(
it
!=
end
())
{
return
it
->
template
get
<
ValueType
>
();
...
...
@@ -21162,7 +21156,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
erase
(
KeyT
&
&
key
)
size_type
erase
(
const
KeyT
&
key
)
{
// this erase only works for objects
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
...
...
@@ -21170,7 +21164,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
const
auto
it
=
m_value
.
object
->
find
(
std
::
forward
<
KeyT
>
(
key
)
);
const
auto
it
=
m_value
.
object
->
find
(
key
);
if
(
it
!=
m_value
.
object
->
end
())
{
m_value
.
object
->
erase
(
it
);
...
...
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