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
aaef7cd2
Unverified
Commit
aaef7cd2
authored
May 04, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
👌
apply review comments
parent
eb0f8d73
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
38 deletions
+66
-38
type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+22
-8
json.hpp
include/nlohmann/json.hpp
+11
-11
json.hpp
single_include/nlohmann/json.hpp
+33
-19
No files found.
include/nlohmann/detail/meta/type_traits.hpp
View file @
aaef7cd2
...
...
@@ -434,16 +434,30 @@ template<typename T1, typename... Args>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
is_constructible
<
T1
,
Args
>
...
>
{};
/// type to check if KeyType can be used as object key
template
<
typename
ComparatorType
,
typename
KeyType
,
typename
ObjectKeyType
,
typename
=
void
>
struct
is_key_type_comparable
{
static
constexpr
bool
value
=
false
;
};
template
<
typename
ComparatorType
,
typename
KeyType
,
typename
ObjectKeyType
>
struct
is_key_type_comparable
<
ComparatorType
,
KeyType
,
ObjectKeyType
,
void_t
<
decltype
(
ComparatorType
()(
std
::
declval
<
KeyType
const
&>
(),
std
::
declval
<
ObjectKeyType
const
&>
())),
decltype
(
ComparatorType
()(
std
::
declval
<
ObjectKeyType
const
&>
(),
std
::
declval
<
KeyType
const
&>
()))
>>
{
static
constexpr
bool
value
=
true
;
};
template
<
typename
BasicJsonType
,
typename
KeyType
>
struct
is_key_type
struct
is_
usable_as_
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
)
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
static
constexpr
bool
value
=
is_key_type_comparable
<
typename
BasicJsonType
::
object_comparator_t
,
typename
BasicJsonType
::
object_t
::
key_type
,
KeyType
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
};
}
// namespace detail
}
// namespace nlohmann
include/nlohmann/json.hpp
View file @
aaef7cd2
...
...
@@ -3527,7 +3527,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
can be thrown.,at__object_t_key_type}
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
reference
at
(
const
KeyT
&
key
)
{
// at only works for objects
...
...
@@ -3576,7 +3576,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
at__object_t_key_type_const}
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
const_reference
at
(
const
KeyT
&
key
)
const
{
// at only works for objects
...
...
@@ -3711,7 +3711,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
reference
operator
[](
KeyT
&&
key
)
{
// implicitly convert null value to an empty object
...
...
@@ -3764,7 +3764,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
const_reference
operator
[](
KeyT
&&
key
)
const
{
// operator[] only works for objects
...
...
@@ -3833,7 +3833,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
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
>
...
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
const
KeyType
&
key
,
ValueType
&&
default_value
)
const
{
// at only works for objects
...
...
@@ -3857,7 +3857,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
template
<
class
KeyType
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
return
value
(
key
,
string_t
(
default_value
));
...
...
@@ -4283,7 +4283,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
erase
(
const
KeyT
&
key
)
{
// this erase only works for objects
...
...
@@ -4379,7 +4379,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
const
KeyT
&
key
)
{
auto
result
=
end
();
...
...
@@ -4397,7 +4397,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@copydoc find(const KeyT&)
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
const
KeyT
&
key
)
const
{
auto
result
=
cend
();
...
...
@@ -4432,7 +4432,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
const
KeyT
&
key
)
const
{
// return 0 for all nonobject types
...
...
@@ -4465,7 +4465,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.6.0
*/
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_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
bool
contains
(
const
KeyT
&
key
)
const
{
return
is_object
()
&&
m_value
.
object
->
find
(
key
)
!=
m_value
.
object
->
end
();
...
...
single_include/nlohmann/json.hpp
View file @
aaef7cd2
...
...
@@ -3829,17 +3829,31 @@ template<typename T1, typename... Args>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
is_constructible
<
T1
,
Args
>
...
>
{};
/// type to check if KeyType can be used as object key
template
<
typename
ComparatorType
,
typename
KeyType
,
typename
ObjectKeyType
,
typename
=
void
>
struct
is_key_type_comparable
{
static
constexpr
bool
value
=
false
;
};
template
<
typename
ComparatorType
,
typename
KeyType
,
typename
ObjectKeyType
>
struct
is_key_type_comparable
<
ComparatorType
,
KeyType
,
ObjectKeyType
,
void_t
<
decltype
(
ComparatorType
()(
std
::
declval
<
KeyType
const
&>
(),
std
::
declval
<
ObjectKeyType
const
&>
())),
decltype
(
ComparatorType
()(
std
::
declval
<
ObjectKeyType
const
&>
(),
std
::
declval
<
KeyType
const
&>
()))
>>
{
static
constexpr
bool
value
=
true
;
};
template
<
typename
BasicJsonType
,
typename
KeyType
>
struct
is_key_type
struct
is_
usable_as_
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
)
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
static
constexpr
bool
value
=
is_key_type_comparable
<
typename
BasicJsonType
::
object_comparator_t
,
typename
BasicJsonType
::
object_t
::
key_type
,
KeyType
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
};
}
// namespace detail
}
// namespace nlohmann
...
...
@@ -20560,7 +20574,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
can be thrown.,at__object_t_key_type}
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
reference
at
(
const
KeyT
&
key
)
{
// at only works for objects
...
...
@@ -20609,7 +20623,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
at__object_t_key_type_const}
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
const_reference
at
(
const
KeyT
&
key
)
const
{
// at only works for objects
...
...
@@ -20744,7 +20758,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
reference
operator
[](
KeyT
&&
key
)
{
// implicitly convert null value to an empty object
...
...
@@ -20797,7 +20811,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template KeyT added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
&&
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
>
...
>
const_reference
operator
[](
KeyT
&&
key
)
const
{
// operator[] only works for objects
...
...
@@ -20866,7 +20880,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
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
>
...
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
ValueType
value
(
const
KeyType
&
key
,
ValueType
&&
default_value
)
const
{
// at only works for objects
...
...
@@ -20890,7 +20904,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
template
<
class
KeyType
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyType
>::
value
>
...
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
return
value
(
key
,
string_t
(
default_value
));
...
...
@@ -21316,7 +21330,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0; template added in version 3.10.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
erase
(
const
KeyT
&
key
)
{
// this erase only works for objects
...
...
@@ -21412,7 +21426,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
iterator
find
(
const
KeyT
&
key
)
{
auto
result
=
end
();
...
...
@@ -21430,7 +21444,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@copydoc find(const KeyT&)
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
const_iterator
find
(
const
KeyT
&
key
)
const
{
auto
result
=
cend
();
...
...
@@ -21465,7 +21479,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
class
KeyT
,
typename
detail
::
enable_if_t
<
detail
::
is_key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
detail
::
is_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
size_type
count
(
const
KeyT
&
key
)
const
{
// return 0 for all nonobject types
...
...
@@ -21498,7 +21512,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.6.0
*/
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_
usable_as_
key_type
<
basic_json_t
,
KeyT
>::
value
>
...
>
bool
contains
(
const
KeyT
&
key
)
const
{
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