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
b18d97df
Unverified
Commit
b18d97df
authored
Jan 02, 2022
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
⏪
undo commit
d8db435c
parent
b01293f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
60 deletions
+8
-60
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+4
-30
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+4
-30
No files found.
include/nlohmann/json.hpp
View file @
b18d97df
...
...
@@ -2111,46 +2111,20 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
}
template
<
typename
T
>
using
Alias
=
T
;
/// @brief access specified object element
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
template
<
typename
T
,
std
::
size_t
n
>
reference
operator
[](
Alias
<
T
[
n
]
>
const
&
key
)
reference
operator
[](
T
*
(
&
key
)[
n
]
)
{
// implicitly convert null value to an empty object
if
(
is_null
())
{
m_type
=
value_t
::
object
;
m_value
.
object
=
create
<
object_t
>
();
assert_invariant
();
}
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
result
=
m_value
.
object
->
emplace
(
key
,
nullptr
);
return
set_parent
(
result
.
first
->
second
);
}
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/// @brief access specified object element
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
template
<
typename
T
,
std
::
size_t
n
>
const_reference
operator
[](
Alias
<
T
[
n
]
>
const
&
key
)
const
const_reference
operator
[](
T
*
(
&
key
)[
n
]
)
const
{
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
it
=
m_value
.
object
->
find
(
key
);
JSON_ASSERT
(
it
!=
m_value
.
object
->
end
());
return
it
->
second
;
}
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/// @brief access specified object element with default value
...
...
single_include/nlohmann/json.hpp
View file @
b18d97df
...
...
@@ -19300,46 +19300,20 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
}
template
<
typename
T
>
using
Alias
=
T
;
/// @brief access specified object element
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
template
<
typename
T
,
std
::
size_t
n
>
reference
operator
[](
Alias
<
T
[
n
]
>
const
&
key
)
reference
operator
[](
T
*
(
&
key
)[
n
]
)
{
// implicitly convert null value to an empty object
if
(
is_null
())
{
m_type
=
value_t
::
object
;
m_value
.
object
=
create
<
object_t
>
();
assert_invariant
();
}
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
result
=
m_value
.
object
->
emplace
(
key
,
nullptr
);
return
set_parent
(
result
.
first
->
second
);
}
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/// @brief access specified object element
/// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/
template
<
typename
T
,
std
::
size_t
n
>
const_reference
operator
[](
Alias
<
T
[
n
]
>
const
&
key
)
const
const_reference
operator
[](
T
*
(
&
key
)[
n
]
)
const
{
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
auto
it
=
m_value
.
object
->
find
(
key
);
JSON_ASSERT
(
it
!=
m_value
.
object
->
end
());
return
it
->
second
;
}
JSON_THROW
(
type_error
::
create
(
305
,
"cannot use operator[] with a string argument with "
+
std
::
string
(
type_name
()),
*
this
));
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/// @brief access specified object element with default value
...
...
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