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
69d74d4e
Unverified
Commit
69d74d4e
authored
Mar 30, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
clean up
parent
f359d74e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
187 deletions
+80
-187
erase.md
doc/mkdocs/docs/api/basic_json/erase.md
+2
-3
type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+12
-0
json.hpp
include/nlohmann/json.hpp
+27
-92
json.hpp
single_include/nlohmann/json.hpp
+39
-92
No files found.
doc/mkdocs/docs/api/basic_json/erase.md
View file @
69d74d4e
...
@@ -12,7 +12,6 @@ const_iterator erase(const_iterator first, const_iterator last);
...
@@ -12,7 +12,6 @@ const_iterator erase(const_iterator first, const_iterator last);
// (3)
// (3)
template
<
typename
KeyT
>
template
<
typename
KeyT
>
size_type
erase
(
KeyT
&&
key
);
size_type
erase
(
KeyT
&&
key
);
size_type
erase
(
const
std
::
string_view
&
key
);
// since C++17
// (4)
// (4)
void
erase
(
const
size_type
idx
);
void
erase
(
const
size_type
idx
);
...
@@ -36,7 +35,7 @@ void erase(const size_type idx);
...
@@ -36,7 +35,7 @@ void erase(const size_type idx);
## Template parameters
## Template parameters
`KeyT`
`KeyT`
: A type convertible to an object key. This can also be a string literal.
: A type convertible to an object key. This can also be a string literal
or a string view (C++17)
.
## Parameters
## Parameters
...
@@ -182,4 +181,4 @@ Strong exception safety: if an exception occurs, the original value stays intact
...
@@ -182,4 +181,4 @@ Strong exception safety: if an exception occurs, the original value stays intact
-
Added in version 1.0.0.
-
Added in version 1.0.0.
-
Added support for binary types in version 3.8.0.
-
Added support for binary types in version 3.8.0.
-
Added
`KeyT`
template
and overload for
`std::string_view`
in version 3.10.0.
-
Added
`KeyT`
template in version 3.10.0.
include/nlohmann/detail/meta/type_traits.hpp
View file @
69d74d4e
...
@@ -394,5 +394,17 @@ struct is_constructible_tuple : std::false_type {};
...
@@ -394,5 +394,17 @@ struct is_constructible_tuple : std::false_type {};
template
<
typename
T1
,
typename
...
Args
>
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
/// type to check if KeyType can be used as object key
template
<
typename
BasicJsonType
,
typename
KeyType
>
struct
is_key_type
{
static
constexpr
bool
value
=
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyType
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
BasicJsonType
::
object_t
::
key_type
>::
value
;
};
}
// namespace detail
}
// namespace detail
}
// namespace nlohmann
}
// namespace nlohmann
include/nlohmann/json.hpp
View file @
69d74d4e
...
@@ -3495,12 +3495,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3495,12 +3495,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
written using `at()`. It also demonstrates the different exceptions that
written using `at()`. It also demonstrates the different exceptions that
can be thrown.,at__object_t_key_type}
can be thrown.,at__object_t_key_type}
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
at
(
const
KeyT
&
key
)
reference
at
(
const
KeyT
&
key
)
{
{
// at only works for objects
// at only works for objects
...
@@ -3548,12 +3544,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3548,12 +3544,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
`at()`. It also demonstrates the different exceptions that can be thrown.,
`at()`. It also demonstrates the different exceptions that can be thrown.,
at__object_t_key_type_const}
at__object_t_key_type_const}
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
at
(
const
KeyT
&
key
)
const
const_reference
at
(
const
KeyT
&
key
)
const
{
{
// at only works for objects
// at only works for objects
...
@@ -3687,13 +3679,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3687,13 +3679,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
@since version 1.0.0; template KeyT added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
reference
operator
[](
KeyT
&&
key
)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
operator
[](
KeyT
&&
key
)
{
{
// implicitly convert null value to an empty object
// implicitly convert null value to an empty object
if
(
is_null
())
if
(
is_null
())
...
@@ -3750,13 +3738,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3750,13 +3738,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
@since version 1.0.0; template KeyT added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
const_reference
operator
[](
KeyT
&&
key
)
const
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
operator
[](
KeyT
&&
key
)
const
{
{
// operator[] only works for objects
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -3822,13 +3806,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3822,13 +3806,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0, KeyType template added in 3.10.0
@since version 1.0.0, KeyType template added in 3.10.0
*/
*/
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
template
<
class
KeyType
,
class
ValueType
,
typename
std
::
enable_if
<
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
&&
(
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
...
@@ -3851,11 +3831,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3851,11 +3831,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@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
*/
*/
template
<
class
KeyType
,
typename
std
::
enable_if
<
template
<
class
KeyType
,
typename
detail
::
enable_if_t
<
#if defined(JSON_HAS_CPP_17)
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
{
return
value
(
key
,
string_t
(
default_value
));
return
value
(
key
,
string_t
(
default_value
));
...
@@ -4256,7 +4233,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4256,7 +4233,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
Removes elements from a JSON object with the key value @a key.
Removes elements from a JSON object with the key value @a key.
@param[in] key value of the elements to remove
@param[in] key value of the elements to remove
@tparam KeyT
a type convertible to an object key
@tparam KeyT
a type convertible to an object key or a std::string_view
@return Number of elements removed. If @a ObjectType is the default
@return Number of elements removed. If @a ObjectType is the default
`std::map` type, the return value will always be `0` (@a key was not
`std::map` type, the return value will always be `0` (@a key was not
...
@@ -4280,53 +4257,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4280,53 +4257,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template added in version 3.10.0
@since version 1.0.0; template added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
#if defined(JSON_HAS_CPP_17)
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
&&
size_type
erase
(
KeyT
&&
key
)
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
KeyT
&&
key
)
{
// this erase only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
return
m_value
.
object
->
erase
(
std
::
forward
<
KeyT
>
(
key
));
}
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
#if defined(JSON_HAS_CPP_17)
/*!
@brief remove element from a JSON object given a key
Removes elements from a JSON object with the key value @a key.
@param[in] key value of the elements to remove
@return Number of elements removed. If @a ObjectType is the default
`std::map` type, the return value will always be `0` (@a key was not
found) or `1` (@a key was found).
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
@liveexample{The example shows the effect of `erase()`.,erase__key_type}
@sa see @ref erase(IteratorType) -- removes the element at a given position
@sa see @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range
@sa see @ref erase(const size_type) -- removes the element from an array at
the given index
@since version 3.10.0
*/
size_type
erase
(
const
std
::
string_view
&
key
)
{
{
// this erase only works for objects
// this erase only works for objects
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
...
@@ -4343,7 +4276,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4343,7 +4276,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
0
;
return
0
;
}
}
#endif
/*!
/*!
@brief remove element from a JSON array given an index
@brief remove element from a JSON array given an index
...
@@ -4421,7 +4353,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4421,7 +4353,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
KeyT
&&
key
)
iterator
find
(
KeyT
&&
key
)
{
{
auto
result
=
end
();
auto
result
=
end
();
...
@@ -4438,7 +4371,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4438,7 +4371,8 @@ 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(KeyT&&)
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
KeyT
&&
key
)
const
const_iterator
find
(
KeyT
&&
key
)
const
{
{
auto
result
=
cend
();
auto
result
=
cend
();
...
@@ -4472,7 +4406,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4472,7 +4406,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
KeyT
&&
key
)
const
size_type
count
(
KeyT
&&
key
)
const
{
{
// return 0 for all nonobject types
// return 0 for all nonobject types
...
@@ -4504,9 +4439,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4504,9 +4439,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.6.0
@since version 3.6.0
*/
*/
template
<
typename
KeyT
,
typename
std
::
enable_if
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
,
int
>::
type
=
0
>
!
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
(
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
(
std
::
forward
<
KeyT
>
(
key
))
!=
m_value
.
object
->
end
();
}
}
...
...
single_include/nlohmann/json.hpp
View file @
69d74d4e
...
@@ -3771,6 +3771,18 @@ struct is_constructible_tuple : std::false_type {};
...
@@ -3771,6 +3771,18 @@ struct is_constructible_tuple : std::false_type {};
template
<
typename
T1
,
typename
...
Args
>
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
/// type to check if KeyType can be used as object key
template
<
typename
BasicJsonType
,
typename
KeyType
>
struct
is_key_type
{
static
constexpr
bool
value
=
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyType
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
BasicJsonType
::
object_t
::
key_type
>::
value
;
};
}
// namespace detail
}
// namespace detail
}
// namespace nlohmann
}
// namespace nlohmann
...
@@ -20384,12 +20396,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20384,12 +20396,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
written using `at()`. It also demonstrates the different exceptions that
written using `at()`. It also demonstrates the different exceptions that
can be thrown.,at__object_t_key_type}
can be thrown.,at__object_t_key_type}
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
at
(
const
KeyT
&
key
)
reference
at
(
const
KeyT
&
key
)
{
{
// at only works for objects
// at only works for objects
...
@@ -20437,12 +20445,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20437,12 +20445,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
`at()`. It also demonstrates the different exceptions that can be thrown.,
`at()`. It also demonstrates the different exceptions that can be thrown.,
at__object_t_key_type_const}
at__object_t_key_type_const}
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
at
(
const
KeyT
&
key
)
const
const_reference
at
(
const
KeyT
&
key
)
const
{
{
// at only works for objects
// at only works for objects
...
@@ -20576,13 +20580,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20576,13 +20580,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
@since version 1.0.0; template KeyT added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
reference
operator
[](
KeyT
&&
key
)
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
operator
[](
KeyT
&&
key
)
{
{
// implicitly convert null value to an empty object
// implicitly convert null value to an empty object
if
(
is_null
())
if
(
is_null
())
...
@@ -20639,13 +20639,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20639,13 +20639,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
@since version 1.0.0; template KeyT added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
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
>
...
>
#if defined(JSON_HAS_CPP_17)
const_reference
operator
[](
KeyT
&&
key
)
const
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
operator
[](
KeyT
&&
key
)
const
{
{
// operator[] only works for objects
// operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -20711,13 +20707,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20711,13 +20707,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0, KeyType template added in 3.10.0
@since version 1.0.0, KeyType template added in 3.10.0
*/
*/
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
template
<
class
KeyType
,
class
ValueType
,
typename
std
::
enable_if
<
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
&&
(
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
...
@@ -20740,11 +20732,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20740,11 +20732,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@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
*/
*/
template
<
class
KeyType
,
typename
std
::
enable_if
<
template
<
class
KeyType
,
typename
detail
::
enable_if_t
<
#if defined(JSON_HAS_CPP_17)
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
{
return
value
(
key
,
string_t
(
default_value
));
return
value
(
key
,
string_t
(
default_value
));
...
@@ -21145,7 +21134,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21145,7 +21134,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
Removes elements from a JSON object with the key value @a key.
Removes elements from a JSON object with the key value @a key.
@param[in] key value of the elements to remove
@param[in] key value of the elements to remove
@tparam KeyT
a type convertible to an object key
@tparam KeyT
a type convertible to an object key or a std::string_view
@return Number of elements removed. If @a ObjectType is the default
@return Number of elements removed. If @a ObjectType is the default
`std::map` type, the return value will always be `0` (@a key was not
`std::map` type, the return value will always be `0` (@a key was not
...
@@ -21169,53 +21158,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21169,53 +21158,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template added in version 3.10.0
@since version 1.0.0; template added in version 3.10.0
*/
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
#if defined(JSON_HAS_CPP_17)
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
&&
size_type
erase
(
KeyT
&&
key
)
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
KeyT
&&
key
)
{
// this erase only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
{
return
m_value
.
object
->
erase
(
std
::
forward
<
KeyT
>
(
key
));
}
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
#if defined(JSON_HAS_CPP_17)
/*!
@brief remove element from a JSON object given a key
Removes elements from a JSON object with the key value @a key.
@param[in] key value of the elements to remove
@return Number of elements removed. If @a ObjectType is the default
`std::map` type, the return value will always be `0` (@a key was not
found) or `1` (@a key was found).
@post References and iterators to the erased elements are invalidated.
Other references and iterators are not affected.
@throw type_error.307 when called on a type other than JSON object;
example: `"cannot use erase() with null"`
@complexity `log(size()) + count(key)`
@liveexample{The example shows the effect of `erase()`.,erase__key_type}
@sa see @ref erase(IteratorType) -- removes the element at a given position
@sa see @ref erase(IteratorType, IteratorType) -- removes the elements in
the given range
@sa see @ref erase(const size_type) -- removes the element from an array at
the given index
@since version 3.10.0
*/
size_type
erase
(
const
std
::
string_view
&
key
)
{
{
// this erase only works for objects
// this erase only works for objects
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
if
(
JSON_HEDLEY_UNLIKELY
(
!
is_object
()))
...
@@ -21232,7 +21177,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21232,7 +21177,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
0
;
return
0
;
}
}
#endif
/*!
/*!
@brief remove element from a JSON array given an index
@brief remove element from a JSON array given an index
...
@@ -21310,7 +21254,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21310,7 +21254,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
KeyT
&&
key
)
iterator
find
(
KeyT
&&
key
)
{
{
auto
result
=
end
();
auto
result
=
end
();
...
@@ -21327,7 +21272,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21327,7 +21272,8 @@ 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(KeyT&&)
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
KeyT
&&
key
)
const
const_iterator
find
(
KeyT
&&
key
)
const
{
{
auto
result
=
cend
();
auto
result
=
cend
();
...
@@ -21361,7 +21307,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21361,7 +21307,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
KeyT
>
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
KeyT
&&
key
)
const
size_type
count
(
KeyT
&&
key
)
const
{
{
// return 0 for all nonobject types
// return 0 for all nonobject types
...
@@ -21393,9 +21340,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21393,9 +21340,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.6.0
@since version 3.6.0
*/
*/
template
<
typename
KeyT
,
typename
std
::
enable_if
<
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
,
int
>::
type
=
0
>
!
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
(
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
(
std
::
forward
<
KeyT
>
(
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