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
08185548
Unverified
Commit
08185548
authored
May 03, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔀
merge develop
parent
4a16e559
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
384 additions
and
221 deletions
+384
-221
json.hpp
single_include/nlohmann/json.hpp
+384
-221
No files found.
single_include/nlohmann/json.hpp
View file @
08185548
...
@@ -49,6 +49,7 @@ SOFTWARE.
...
@@ -49,6 +49,7 @@ SOFTWARE.
// #include <nlohmann/adl_serializer.hpp>
// #include <nlohmann/adl_serializer.hpp>
#include <type_traits>
#include <utility>
#include <utility>
// #include <nlohmann/detail/conversions/from_json.hpp>
// #include <nlohmann/detail/conversions/from_json.hpp>
...
@@ -2229,15 +2230,20 @@ JSON_HEDLEY_DIAGNOSTIC_POP
...
@@ -2229,15 +2230,20 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#endif
#endif
// C++ language standard detection
// C++ language standard detection
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
// if the user manually specified the used c++ version this is skipped
#define JSON_HAS_CPP_20
#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
#define JSON_HAS_CPP_17
#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
#define JSON_HAS_CPP_14
#define JSON_HAS_CPP_20
#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
#define JSON_HAS_CPP_14
#endif
// the cpp 11 flag is always specified because it is the minimal required version
#define JSON_HAS_CPP_11
#endif
#endif
// disable documentation warnings on clang
// disable documentation warnings on clang
...
@@ -3166,6 +3172,18 @@ constexpr T static_const<T>::value;
...
@@ -3166,6 +3172,18 @@ constexpr T static_const<T>::value;
}
// namespace detail
}
// namespace detail
}
// namespace nlohmann
}
// namespace nlohmann
// #include <nlohmann/detail/meta/identity_tag.hpp>
namespace
nlohmann
{
namespace
detail
{
// dispatching helper struct
template
<
class
T
>
struct
identity_tag
{};
}
// namespace detail
}
// namespace nlohmann
// #include <nlohmann/detail/meta/type_traits.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
...
@@ -3483,8 +3501,7 @@ struct is_getable
...
@@ -3483,8 +3501,7 @@ struct is_getable
};
};
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_from_json
<
BasicJsonType
,
T
,
struct
has_from_json
<
BasicJsonType
,
T
,
enable_if_t
<
!
is_basic_json
<
T
>::
value
>>
enable_if_t
<
!
is_basic_json
<
T
>::
value
>>
{
{
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
;
...
@@ -3528,6 +3545,52 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
...
@@ -3528,6 +3545,52 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
// is_ functions //
// is_ functions //
///////////////////
///////////////////
// https://en.cppreference.com/w/cpp/types/conjunction
template
<
class
...
>
struct
conjunction
:
std
::
true_type
{
};
template
<
class
B1
>
struct
conjunction
<
B1
>
:
B1
{
};
template
<
class
B1
,
class
...
Bn
>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
template
<
typename
T
>
struct
is_default_constructible
:
std
::
is_default_constructible
<
T
>
{};
template
<
typename
T1
,
typename
T2
>
struct
is_default_constructible
<
std
::
pair
<
T1
,
T2
>>
:
conjunction
<
is_default_constructible
<
T1
>
,
is_default_constructible
<
T2
>>
{};
template
<
typename
T1
,
typename
T2
>
struct
is_default_constructible
<
const
std
::
pair
<
T1
,
T2
>>
:
conjunction
<
is_default_constructible
<
T1
>
,
is_default_constructible
<
T2
>>
{};
template
<
typename
...
Ts
>
struct
is_default_constructible
<
std
::
tuple
<
Ts
...
>>
:
conjunction
<
is_default_constructible
<
Ts
>
...
>
{};
template
<
typename
...
Ts
>
struct
is_default_constructible
<
const
std
::
tuple
<
Ts
...
>>
:
conjunction
<
is_default_constructible
<
Ts
>
...
>
{};
template
<
typename
T
,
typename
...
Args
>
struct
is_constructible
:
std
::
is_constructible
<
T
,
Args
...
>
{};
template
<
typename
T1
,
typename
T2
>
struct
is_constructible
<
std
::
pair
<
T1
,
T2
>>
:
is_default_constructible
<
std
::
pair
<
T1
,
T2
>>
{};
template
<
typename
T1
,
typename
T2
>
struct
is_constructible
<
const
std
::
pair
<
T1
,
T2
>>
:
is_default_constructible
<
const
std
::
pair
<
T1
,
T2
>>
{};
template
<
typename
...
Ts
>
struct
is_constructible
<
std
::
tuple
<
Ts
...
>>
:
is_default_constructible
<
std
::
tuple
<
Ts
...
>>
{};
template
<
typename
...
Ts
>
struct
is_constructible
<
const
std
::
tuple
<
Ts
...
>>
:
is_default_constructible
<
const
std
::
tuple
<
Ts
...
>>
{};
template
<
typename
T
,
typename
=
void
>
template
<
typename
T
,
typename
=
void
>
struct
is_iterator_traits
:
std
::
false_type
{};
struct
is_iterator_traits
:
std
::
false_type
{};
...
@@ -3570,9 +3633,9 @@ struct is_compatible_object_type_impl <
...
@@ -3570,9 +3633,9 @@ struct is_compatible_object_type_impl <
// macOS's is_constructible does not play well with nonesuch...
// macOS's is_constructible does not play well with nonesuch...
static
constexpr
bool
value
=
static
constexpr
bool
value
=
std
::
is_constructible
<
typename
object_t
::
key_type
,
is_constructible
<
typename
object_t
::
key_type
,
typename
CompatibleObjectType
::
key_type
>::
value
&&
typename
CompatibleObjectType
::
key_type
>::
value
&&
std
::
is_constructible
<
typename
object_t
::
mapped_type
,
is_constructible
<
typename
object_t
::
mapped_type
,
typename
CompatibleObjectType
::
mapped_type
>::
value
;
typename
CompatibleObjectType
::
mapped_type
>::
value
;
};
};
...
@@ -3593,10 +3656,10 @@ struct is_constructible_object_type_impl <
...
@@ -3593,10 +3656,10 @@ struct is_constructible_object_type_impl <
using
object_t
=
typename
BasicJsonType
::
object_t
;
using
object_t
=
typename
BasicJsonType
::
object_t
;
static
constexpr
bool
value
=
static
constexpr
bool
value
=
(
std
::
is_default_constructible
<
ConstructibleObjectType
>::
value
&&
(
is_default_constructible
<
ConstructibleObjectType
>::
value
&&
(
std
::
is_move_assignable
<
ConstructibleObjectType
>::
value
||
(
std
::
is_move_assignable
<
ConstructibleObjectType
>::
value
||
std
::
is_copy_assignable
<
ConstructibleObjectType
>::
value
)
&&
std
::
is_copy_assignable
<
ConstructibleObjectType
>::
value
)
&&
(
std
::
is_constructible
<
typename
ConstructibleObjectType
::
key_type
,
(
is_constructible
<
typename
ConstructibleObjectType
::
key_type
,
typename
object_t
::
key_type
>::
value
&&
typename
object_t
::
key_type
>::
value
&&
std
::
is_same
<
std
::
is_same
<
typename
object_t
::
mapped_type
,
typename
object_t
::
mapped_type
,
...
@@ -3624,7 +3687,7 @@ struct is_compatible_string_type_impl <
...
@@ -3624,7 +3687,7 @@ struct is_compatible_string_type_impl <
value_type_t
,
CompatibleStringType
>::
value
>>
value_type_t
,
CompatibleStringType
>::
value
>>
{
{
static
constexpr
auto
value
=
static
constexpr
auto
value
=
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
CompatibleStringType
>::
value
;
is_constructible
<
typename
BasicJsonType
::
string_t
,
CompatibleStringType
>::
value
;
};
};
template
<
typename
BasicJsonType
,
typename
ConstructibleStringType
>
template
<
typename
BasicJsonType
,
typename
ConstructibleStringType
>
...
@@ -3642,7 +3705,7 @@ struct is_constructible_string_type_impl <
...
@@ -3642,7 +3705,7 @@ struct is_constructible_string_type_impl <
value_type_t
,
ConstructibleStringType
>::
value
>>
value_type_t
,
ConstructibleStringType
>::
value
>>
{
{
static
constexpr
auto
value
=
static
constexpr
auto
value
=
std
::
is_constructible
<
ConstructibleStringType
,
is_constructible
<
ConstructibleStringType
,
typename
BasicJsonType
::
string_t
>::
value
;
typename
BasicJsonType
::
string_t
>::
value
;
};
};
...
@@ -3665,7 +3728,7 @@ struct is_compatible_array_type_impl <
...
@@ -3665,7 +3728,7 @@ struct is_compatible_array_type_impl <
iterator_traits
<
CompatibleArrayType
>>::
value
>>
iterator_traits
<
CompatibleArrayType
>>::
value
>>
{
{
static
constexpr
bool
value
=
static
constexpr
bool
value
=
std
::
is_constructible
<
BasicJsonType
,
is_constructible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
;
typename
CompatibleArrayType
::
value_type
>::
value
;
};
};
...
@@ -3688,7 +3751,7 @@ struct is_constructible_array_type_impl <
...
@@ -3688,7 +3751,7 @@ struct is_constructible_array_type_impl <
BasicJsonType
,
ConstructibleArrayType
,
BasicJsonType
,
ConstructibleArrayType
,
enable_if_t
<
!
std
::
is_same
<
ConstructibleArrayType
,
enable_if_t
<
!
std
::
is_same
<
ConstructibleArrayType
,
typename
BasicJsonType
::
value_type
>::
value
&&
typename
BasicJsonType
::
value_type
>::
value
&&
std
::
is_default_constructible
<
ConstructibleArrayType
>::
value
&&
is_default_constructible
<
ConstructibleArrayType
>::
value
&&
(
std
::
is_move_assignable
<
ConstructibleArrayType
>::
value
||
(
std
::
is_move_assignable
<
ConstructibleArrayType
>::
value
||
std
::
is_copy_assignable
<
ConstructibleArrayType
>::
value
)
&&
std
::
is_copy_assignable
<
ConstructibleArrayType
>::
value
)
&&
is_detected
<
value_type_t
,
ConstructibleArrayType
>::
value
&&
is_detected
<
value_type_t
,
ConstructibleArrayType
>::
value
&&
...
@@ -3732,7 +3795,7 @@ struct is_compatible_integer_type_impl <
...
@@ -3732,7 +3795,7 @@ struct is_compatible_integer_type_impl <
using
CompatibleLimits
=
std
::
numeric_limits
<
CompatibleNumberIntegerType
>
;
using
CompatibleLimits
=
std
::
numeric_limits
<
CompatibleNumberIntegerType
>
;
static
constexpr
auto
value
=
static
constexpr
auto
value
=
std
::
is_constructible
<
RealIntegerType
,
is_constructible
<
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
&&
CompatibleNumberIntegerType
>::
value
&&
CompatibleLimits
::
is_integer
&&
CompatibleLimits
::
is_integer
&&
RealLimits
::
is_signed
==
CompatibleLimits
::
is_signed
;
RealLimits
::
is_signed
==
CompatibleLimits
::
is_signed
;
...
@@ -3759,18 +3822,11 @@ template<typename BasicJsonType, typename CompatibleType>
...
@@ -3759,18 +3822,11 @@ template<typename BasicJsonType, typename CompatibleType>
struct
is_compatible_type
struct
is_compatible_type
:
is_compatible_type_impl
<
BasicJsonType
,
CompatibleType
>
{};
:
is_compatible_type_impl
<
BasicJsonType
,
CompatibleType
>
{};
// https://en.cppreference.com/w/cpp/types/conjunction
template
<
class
...
>
struct
conjunction
:
std
::
true_type
{
};
template
<
class
B1
>
struct
conjunction
<
B1
>
:
B1
{
};
template
<
class
B1
,
class
...
Bn
>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
template
<
typename
T1
,
typename
T2
>
template
<
typename
T1
,
typename
T2
>
struct
is_constructible_tuple
:
std
::
false_type
{};
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
<
is_constructible
<
T1
,
Args
>
...
>
{};
/// type to check if KeyType can be used as object key
/// type to check if KeyType can be used as object key
template
<
typename
BasicJsonType
,
typename
KeyType
>
template
<
typename
BasicJsonType
,
typename
KeyType
>
...
@@ -3784,7 +3840,6 @@ struct is_key_type
...
@@ -3784,7 +3840,6 @@ struct is_key_type
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
iterator
>::
value
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
&&
!
std
::
is_same
<
KeyType
,
typename
BasicJsonType
::
const_iterator
>::
value
;
};
};
}
// namespace detail
}
// namespace detail
}
// namespace nlohmann
}
// namespace nlohmann
...
@@ -3960,7 +4015,10 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
...
@@ -3960,7 +4015,10 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
}
}
}
}
template
<
typename
BasicJsonType
,
typename
ConstructibleArrayType
>
template
<
typename
BasicJsonType
,
typename
ConstructibleArrayType
,
enable_if_t
<
std
::
is_assignable
<
ConstructibleArrayType
&
,
ConstructibleArrayType
>::
value
,
int
>
=
0
>
auto
from_json_array_impl
(
const
BasicJsonType
&
j
,
ConstructibleArrayType
&
arr
,
priority_tag
<
1
>
/*unused*/
)
auto
from_json_array_impl
(
const
BasicJsonType
&
j
,
ConstructibleArrayType
&
arr
,
priority_tag
<
1
>
/*unused*/
)
->
decltype
(
->
decltype
(
arr
.
reserve
(
std
::
declval
<
typename
ConstructibleArrayType
::
size_type
>
()),
arr
.
reserve
(
std
::
declval
<
typename
ConstructibleArrayType
::
size_type
>
()),
...
@@ -3981,7 +4039,10 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
...
@@ -3981,7 +4039,10 @@ auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, p
arr
=
std
::
move
(
ret
);
arr
=
std
::
move
(
ret
);
}
}
template
<
typename
BasicJsonType
,
typename
ConstructibleArrayType
>
template
<
typename
BasicJsonType
,
typename
ConstructibleArrayType
,
enable_if_t
<
std
::
is_assignable
<
ConstructibleArrayType
&
,
ConstructibleArrayType
>::
value
,
int
>
=
0
>
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
ConstructibleArrayType
&
arr
,
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
ConstructibleArrayType
&
arr
,
priority_tag
<
0
>
/*unused*/
)
priority_tag
<
0
>
/*unused*/
)
{
{
...
@@ -4020,6 +4081,25 @@ void())
...
@@ -4020,6 +4081,25 @@ void())
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{});
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
...
Idx
>
std
::
array
<
T
,
sizeof
...(
Idx
)
>
from_json_inplace_array_impl
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
sizeof
...(
Idx
)
>>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
)
{
return
{
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
T
>
()...
}
};
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
N
>>
tag
)
->
decltype
(
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{}))
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
()),
j
));
}
return
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{});
}
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
binary_t
&
bin
)
void
from_json
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
binary_t
&
bin
)
{
{
...
@@ -4095,22 +4175,47 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
...
@@ -4095,22 +4175,47 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
}
}
}
}
template
<
typename
BasicJsonType
,
typename
...
Args
,
std
::
size_t
...
Idx
>
std
::
tuple
<
Args
...
>
from_json_tuple_impl_base
(
BasicJsonType
&&
j
,
index_sequence
<
Idx
...
>
/*unused*/
)
{
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
Args
>
()...);
}
template
<
typename
BasicJsonType
,
class
A1
,
class
A2
>
std
::
pair
<
A1
,
A2
>
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
pair
<
A1
,
A2
>>
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
{
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
0
).
template
get
<
A1
>
(),
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>
()};
}
template
<
typename
BasicJsonType
,
typename
A1
,
typename
A2
>
template
<
typename
BasicJsonType
,
typename
A1
,
typename
A2
>
void
from_json
(
const
BasicJsonType
&
j
,
std
::
pair
<
A1
,
A2
>&
p
)
void
from_json
_tuple_impl
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
,
priority_tag
<
1
>
/*unused*/
)
{
{
p
=
{
j
.
at
(
0
).
template
get
<
A1
>
(),
j
.
at
(
1
).
template
get
<
A2
>
()}
;
p
=
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
std
::
pair
<
A1
,
A2
>>
{},
priority_tag
<
0
>
{})
;
}
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
from_json_tuple_impl
(
const
BasicJsonType
&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
)
std
::
tuple
<
Args
...
>
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
tuple
<
Args
...
>>
/*unused*/
,
priority_tag
<
2
>
/*unused*/
)
{
{
t
=
std
::
make_tuple
(
j
.
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>::
type
>
()...
);
return
from_json_tuple_impl_base
<
BasicJsonType
,
Args
...
>
(
std
::
forward
<
BasicJsonType
>
(
j
),
index_sequence_for
<
Args
...
>
{}
);
}
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
from_json
(
const
BasicJsonType
&
j
,
std
::
tuple
<
Args
...
>&
t
)
void
from_json
_tuple_impl
(
BasicJsonType
&&
j
,
std
::
tuple
<
Args
...
>&
t
,
priority_tag
<
3
>
/*unused*/
)
{
{
from_json_tuple_impl
(
j
,
t
,
index_sequence_for
<
Args
...
>
{});
t
=
from_json_tuple_impl_base
<
BasicJsonType
,
Args
...
>
(
std
::
forward
<
BasicJsonType
>
(
j
),
index_sequence_for
<
Args
...
>
{});
}
template
<
typename
BasicJsonType
,
typename
TupleRelated
>
auto
from_json
(
BasicJsonType
&&
j
,
TupleRelated
&&
t
)
->
decltype
(
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
priority_tag
<
3
>
{}))
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
()),
j
));
}
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
priority_tag
<
3
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
Key
,
typename
Value
,
typename
Compare
,
typename
Allocator
,
template
<
typename
BasicJsonType
,
typename
Key
,
typename
Value
,
typename
Compare
,
typename
Allocator
,
...
@@ -4156,11 +4261,11 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
...
@@ -4156,11 +4261,11 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
struct
from_json_fn
struct
from_json_fn
{
{
template
<
typename
BasicJsonType
,
typename
T
>
template
<
typename
BasicJsonType
,
typename
T
>
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
noexcept
(
noexcept
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
)
)))
->
decltype
(
from_json
(
j
,
val
),
void
(
))
->
decltype
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
)
))
{
{
return
from_json
(
j
,
val
);
return
from_json
(
j
,
std
::
forward
<
T
>
(
val
)
);
}
}
};
};
}
// namespace detail
}
// namespace detail
...
@@ -4745,11 +4850,15 @@ constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
...
@@ -4745,11 +4850,15 @@ constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
}
// namespace
}
// namespace
}
// namespace nlohmann
}
// namespace nlohmann
// #include <nlohmann/detail/meta/identity_tag.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
namespace
nlohmann
namespace
nlohmann
{
{
template
<
typename
,
typename
>
template
<
typename
ValueType
,
typename
>
struct
adl_serializer
struct
adl_serializer
{
{
/*!
/*!
...
@@ -4758,11 +4867,13 @@ struct adl_serializer
...
@@ -4758,11 +4867,13 @@ struct adl_serializer
This function is usually called by the `get()` function of the
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for default-constructible value types.
@param[in] j JSON value to read from
@param[in] j JSON value to read from
@param[in,out] val value to write to
@param[in,out] val value to write to
*/
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
template
<
typename
BasicJsonType
,
typename
TargetType
=
ValueType
>
static
auto
from_json
(
BasicJsonType
&&
j
,
Value
Type
&
val
)
noexcept
(
static
auto
from_json
(
BasicJsonType
&&
j
,
Target
Type
&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
),
void
())
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
),
void
())
{
{
...
@@ -4770,6 +4881,26 @@ struct adl_serializer
...
@@ -4770,6 +4881,26 @@ struct adl_serializer
}
}
/*!
/*!
@brief convert a JSON value to any value type
This function is usually called by the `get()` function of the
@ref basic_json class (either explicit or via conversion operators).
@note This function is chosen for value types which are not default-constructible.
@param[in] j JSON value to read from
@return copy of the JSON value, converted to @a ValueType
*/
template
<
typename
BasicJsonType
,
typename
TargetType
=
ValueType
>
static
auto
from_json
(
BasicJsonType
&&
j
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
identity_tag
<
TargetType
>
{})))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
identity_tag
<
TargetType
>
{}))
{
return
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
identity_tag
<
TargetType
>
{});
}
/*!
@brief convert any value type to a JSON value
@brief convert any value type to a JSON value
This function is usually called by the constructors of the @ref basic_json
This function is usually called by the constructors of the @ref basic_json
...
@@ -4778,15 +4909,14 @@ struct adl_serializer
...
@@ -4778,15 +4909,14 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in,out] j JSON value to write to
@param[in] val value to read from
@param[in] val value to read from
*/
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
template
<
typename
BasicJsonType
,
typename
TargetType
=
ValueType
>
static
auto
to_json
(
BasicJsonType
&
j
,
ValueType
&&
val
)
noexcept
(
static
auto
to_json
(
BasicJsonType
&
j
,
TargetType
&&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Value
Type
>
(
val
))))
noexcept
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Target
Type
>
(
val
))))
->
decltype
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Value
Type
>
(
val
)),
void
())
->
decltype
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Target
Type
>
(
val
)),
void
())
{
{
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Value
Type
>
(
val
));
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
Target
Type
>
(
val
));
}
}
};
};
}
// namespace nlohmann
}
// namespace nlohmann
// #include <nlohmann/byte_container_with_subtype.hpp>
// #include <nlohmann/byte_container_with_subtype.hpp>
...
@@ -6537,7 +6667,7 @@ class lexer : public lexer_base<BasicJsonType>
...
@@ -6537,7 +6667,7 @@ class lexer : public lexer_base<BasicJsonType>
/*!
/*!
@brief scan a string literal
@brief scan a string literal
This function scans a string according to Sect. 7 of RFC
71
59. While
This function scans a string according to Sect. 7 of RFC
82
59. While
scanning, bytes are escaped and copied into buffer token_buffer. Then the
scanning, bytes are escaped and copied into buffer token_buffer. Then the
function returns successfully, token_buffer is *not* null-terminated (as it
function returns successfully, token_buffer is *not* null-terminated (as it
may contain \0 bytes), and token_buffer.size() is the number of bytes in the
may contain \0 bytes), and token_buffer.size() is the number of bytes in the
...
@@ -7227,10 +7357,10 @@ class lexer : public lexer_base<BasicJsonType>
...
@@ -7227,10 +7357,10 @@ class lexer : public lexer_base<BasicJsonType>
/*!
/*!
@brief scan a number literal
@brief scan a number literal
This function scans a string according to Sect. 6 of RFC
71
59.
This function scans a string according to Sect. 6 of RFC
82
59.
The function is realized with a deterministic finite state machine derived
The function is realized with a deterministic finite state machine derived
from the grammar described in RFC
71
59. Starting in state "init", the
from the grammar described in RFC
82
59. Starting in state "init", the
input is read and used to determined the next state. Only state "done"
input is read and used to determined the next state. Only state "done"
accepts the number. State "error" is a trap state to model errors. In the
accepts the number. State "error" is a trap state to model errors. In the
table below, "anything" means any character but the ones listed before.
table below, "anything" means any character but the ones listed before.
...
@@ -17066,8 +17196,8 @@ The invariants are checked by member function assert_invariant().
...
@@ -17066,8 +17196,8 @@ The invariants are checked by member function assert_invariant().
@note ObjectType trick from https://stackoverflow.com/a/9860911
@note ObjectType trick from https://stackoverflow.com/a/9860911
@endinternal
@endinternal
@see [RFC
71
59: The JavaScript Object Notation (JSON) Data Interchange
@see [RFC
82
59: The JavaScript Object Notation (JSON) Data Interchange
Format](http
://rfc7159.net/rfc71
59)
Format](http
s://tools.ietf.org/html/rfc82
59)
@since version 1.0.0
@since version 1.0.0
...
@@ -17328,7 +17458,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17328,7 +17458,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for an object
@brief a type for an object
[RFC
7159](http://rfc7159.net/rfc71
59) describes JSON objects as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes JSON objects as follows:
> An object is an unordered collection of zero or more name/value pairs,
> An object is an unordered collection of zero or more name/value pairs,
> where a name is a string and a value is a string, number, boolean, null,
> where a name is a string and a value is a string, number, boolean, null,
> object, or array.
> object, or array.
...
@@ -17382,7 +17512,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17382,7 +17512,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### Limits
#### Limits
[RFC
7159](http://rfc7159.net/rfc71
59) specifies:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) specifies:
> An implementation may set limits on the maximum depth of nesting.
> An implementation may set limits on the maximum depth of nesting.
In this class, the object's limit of nesting is not explicitly constrained.
In this class, the object's limit of nesting is not explicitly constrained.
...
@@ -17405,7 +17535,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17405,7 +17535,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
name/value pairs in a different order than they were originally stored. In
name/value pairs in a different order than they were originally stored. In
fact, keys will be traversed in alphabetical order as `std::map` with
fact, keys will be traversed in alphabetical order as `std::map` with
`std::less` is used by default. Please note this behavior conforms to [RFC
`std::less` is used by default. Please note this behavior conforms to [RFC
7159](http://rfc7159.net/rfc71
59), because any order implements the
8259](https://tools.ietf.org/html/rfc82
59), because any order implements the
specified "unordered" nature of JSON objects.
specified "unordered" nature of JSON objects.
*/
*/
using
object_t
=
ObjectType
<
StringType
,
using
object_t
=
ObjectType
<
StringType
,
...
@@ -17417,7 +17547,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17417,7 +17547,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for an array
@brief a type for an array
[RFC
7159](http://rfc7159.net/rfc71
59) describes JSON arrays as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes JSON arrays as follows:
> An array is an ordered sequence of zero or more values.
> An array is an ordered sequence of zero or more values.
To store objects in C++, a type is defined by the template parameters
To store objects in C++, a type is defined by the template parameters
...
@@ -17441,7 +17571,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17441,7 +17571,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### Limits
#### Limits
[RFC
7159](http://rfc7159.net/rfc71
59) specifies:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) specifies:
> An implementation may set limits on the maximum depth of nesting.
> An implementation may set limits on the maximum depth of nesting.
In this class, the array's limit of nesting is not explicitly constrained.
In this class, the array's limit of nesting is not explicitly constrained.
...
@@ -17463,7 +17593,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17463,7 +17593,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for a string
@brief a type for a string
[RFC
7159](http://rfc7159.net/rfc71
59) describes JSON strings as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes JSON strings as follows:
> A string is a sequence of zero or more Unicode characters.
> A string is a sequence of zero or more Unicode characters.
To store objects in C++, a type is defined by the template parameter
To store objects in C++, a type is defined by the template parameter
...
@@ -17490,7 +17620,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17490,7 +17620,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### String comparison
#### String comparison
[RFC
7159](http://rfc7159.net/rfc71
59) states:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) states:
> Software implementations are typically required to test names of object
> Software implementations are typically required to test names of object
> members for equality. Implementations that transform the textual
> members for equality. Implementations that transform the textual
> representation into sequences of Unicode code units and then perform the
> representation into sequences of Unicode code units and then perform the
...
@@ -17516,7 +17646,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17516,7 +17646,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for a boolean
@brief a type for a boolean
[RFC
7159](http://rfc7159.net/rfc71
59) implicitly describes a boolean as a
[RFC
8259](https://tools.ietf.org/html/rfc82
59) implicitly describes a boolean as a
type which differentiates the two literals `true` and `false`.
type which differentiates the two literals `true` and `false`.
To store objects in C++, a type is defined by the template parameter @a
To store objects in C++, a type is defined by the template parameter @a
...
@@ -17542,7 +17672,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17542,7 +17672,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for a number (integer)
@brief a type for a number (integer)
[RFC
7159](http://rfc7159.net/rfc71
59) describes numbers as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes numbers as follows:
> The representation of numbers is similar to that used in most
> The representation of numbers is similar to that used in most
> programming languages. A number is represented in base 10 using decimal
> programming languages. A number is represented in base 10 using decimal
> digits. It contains an integer component that may be prefixed with an
> digits. It contains an integer component that may be prefixed with an
...
@@ -17580,7 +17710,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17580,7 +17710,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### Limits
#### Limits
[RFC
7159](http://rfc7159.net/rfc71
59) specifies:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) specifies:
> An implementation may set limits on the range and precision of numbers.
> An implementation may set limits on the range and precision of numbers.
When the default type is used, the maximal integer number that can be
When the default type is used, the maximal integer number that can be
...
@@ -17591,7 +17721,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17591,7 +17721,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
will be automatically be stored as @ref number_unsigned_t or @ref
will be automatically be stored as @ref number_unsigned_t or @ref
number_float_t.
number_float_t.
[RFC
7159](http://rfc7159.net/rfc71
59) further states:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) further states:
> Note that when such software is used, numbers that are integers and are
> Note that when such software is used, numbers that are integers and are
> in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense
> in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense
> that implementations will agree exactly on their numeric values.
> that implementations will agree exactly on their numeric values.
...
@@ -17614,7 +17744,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17614,7 +17744,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for a number (unsigned)
@brief a type for a number (unsigned)
[RFC
7159](http://rfc7159.net/rfc71
59) describes numbers as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes numbers as follows:
> The representation of numbers is similar to that used in most
> The representation of numbers is similar to that used in most
> programming languages. A number is represented in base 10 using decimal
> programming languages. A number is represented in base 10 using decimal
> digits. It contains an integer component that may be prefixed with an
> digits. It contains an integer component that may be prefixed with an
...
@@ -17652,7 +17782,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17652,7 +17782,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### Limits
#### Limits
[RFC
7159](http://rfc7159.net/rfc71
59) specifies:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) specifies:
> An implementation may set limits on the range and precision of numbers.
> An implementation may set limits on the range and precision of numbers.
When the default type is used, the maximal integer number that can be
When the default type is used, the maximal integer number that can be
...
@@ -17662,7 +17792,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17662,7 +17792,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
deserialization, too large or small integer numbers will be automatically
deserialization, too large or small integer numbers will be automatically
be stored as @ref number_integer_t or @ref number_float_t.
be stored as @ref number_integer_t or @ref number_float_t.
[RFC
7159](http://rfc7159.net/rfc71
59) further states:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) further states:
> Note that when such software is used, numbers that are integers and are
> Note that when such software is used, numbers that are integers and are
> in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense
> in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense
> that implementations will agree exactly on their numeric values.
> that implementations will agree exactly on their numeric values.
...
@@ -17685,7 +17815,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17685,7 +17815,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/*!
/*!
@brief a type for a number (floating-point)
@brief a type for a number (floating-point)
[RFC
7159](http://rfc7159.net/rfc71
59) describes numbers as follows:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) describes numbers as follows:
> The representation of numbers is similar to that used in most
> The representation of numbers is similar to that used in most
> programming languages. A number is represented in base 10 using decimal
> programming languages. A number is represented in base 10 using decimal
> digits. It contains an integer component that may be prefixed with an
> digits. It contains an integer component that may be prefixed with an
...
@@ -17723,7 +17853,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -17723,7 +17853,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#### Limits
#### Limits
[RFC
7159](http://rfc7159.net/rfc71
59) states:
[RFC
8259](https://tools.ietf.org/html/rfc82
59) states:
> This specification allows implementations to set limits on the range and
> This specification allows implementations to set limits on the range and
> precision of numbers accepted. Since software that implements IEEE
> precision of numbers accepted. Since software that implements IEEE
> 754-2008 binary64 (double precision) numbers is generally available and
> 754-2008 binary64 (double precision) numbers is generally available and
...
@@ -18161,9 +18291,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -18161,9 +18291,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}));
}));
}
}
JSON_CATCH
(...)
{}
// LCOV_EXCL_LINE
JSON_CATCH
(...)
{}
// LCOV_EXCL_LINE
#else
static_cast
<
void
>
(
check_parents
);
#endif
#endif
static_cast
<
void
>
(
check_parents
);
}
}
void
set_parents
()
void
set_parents
()
...
@@ -19826,50 +19955,53 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19826,50 +19955,53 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @{
/// @{
/*!
/*!
@brief get
special-case overload
@brief get
a pointer value (implicit)
This overloads avoids a lot of template boilerplate, it can be seen as th
e
Implicit pointer access to the internally stored JSON value. No copies ar
e
identity method
made.
@tparam BasicJsonType == @ref basic_json
@warning Writing data to the pointee of the result yields an undefined
state.
@return a copy of *this
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
assertion.
@return pointer to the internally stored JSON value if the requested
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
@complexity Constant.
@complexity Constant.
@since version 2.1.0
@liveexample{The example below shows how pointers to internal values of a
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
match.,get_ptr}
@since version 1.0.0
*/
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_same
<
typename
std
::
remove_const
<
BasicJsonType
>::
type
,
basic_json_t
>::
value
,
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
int
>
=
0
>
auto
get_ptr
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
basic_json
get
()
const
{
{
return
*
this
;
// delegate the call to get_impl_ptr<>()
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
/*!
/*!
@brief get special-case overload
@brief get a pointer value (implicit)
@copydoc get_ptr()
This overloads converts the current @ref basic_json in a different
@ref basic_json type
@tparam BasicJsonType == @ref basic_json
@return a copy of *this, converted into @a BasicJsonType
@complexity Depending on the implementation of the called `from_json()`
method.
@since version 3.2.0
*/
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
template
<
typename
PointerType
,
typename
std
::
enable_if
<
!
std
::
is_same
<
BasicJsonType
,
basic_json
>::
value
&&
std
::
is_pointer
<
PointerType
>::
value
&&
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
BasicJsonType
get
()
const
constexpr
auto
get_ptr
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
return
*
this
;
// delegate the call to get_impl_ptr<>() const
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
}
private
:
/*!
/*!
@brief get a value (explicit)
@brief get a value (explicit)
...
@@ -19893,7 +20025,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19893,7 +20025,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
- @ref json_serializer<ValueType> does not have a `from_json()` method of
- @ref json_serializer<ValueType> does not have a `from_json()` method of
the form `ValueType from_json(const basic_json&)`
the form `ValueType from_json(const basic_json&)`
@tparam ValueTypeCV the provided value type
@tparam ValueType the returned value type
@tparam ValueType the returned value type
@return copy of the JSON value, converted to @a ValueType
@return copy of the JSON value, converted to @a ValueType
...
@@ -19909,23 +20040,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19909,23 +20040,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 2.1.0
@since version 2.1.0
*/
*/
template
<
typename
ValueType
CV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
template
<
typename
ValueType
,
detail
::
enable_if_t
<
detail
::
enable_if_t
<
!
detail
::
is_basic_json
<
ValueType
>::
value
&&
detail
::
is_default_constructible
<
ValueType
>::
value
&&
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
&&
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
,
!
detail
::
has_non_default_from_json
<
basic_json_t
,
ValueType
>::
value
,
int
>
=
0
>
int
>
=
0
>
ValueType
get
(
)
const
noexcept
(
noexcept
(
ValueType
get
_impl
(
detail
::
priority_tag
<
0
>
/*unused*/
)
const
noexcept
(
noexcept
(
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
ValueType
&>
())))
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
ValueType
&>
())))
{
{
// we cannot static_assert on ValueTypeCV being non-const, because
// there is support for get<const basic_json_t>(), which is why we
// still need the uncvref
static_assert
(
!
std
::
is_reference
<
ValueTypeCV
>::
value
,
"get() cannot be used with reference types, you might want to use get_ref()"
);
static_assert
(
std
::
is_default_constructible
<
ValueType
>::
value
,
"types must be DefaultConstructible when used with get()"
);
ValueType
ret
{};
ValueType
ret
{};
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
ret
);
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
ret
);
return
ret
;
return
ret
;
...
@@ -19942,7 +20064,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19942,7 +20064,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
The function is equivalent to executing
The function is equivalent to executing
@code {.cpp}
@code {.cpp}
return JSONSerializer<ValueType
CV
>::from_json(*this);
return JSONSerializer<ValueType>::from_json(*this);
@endcode
@endcode
This overloads is chosen if:
This overloads is chosen if:
...
@@ -19953,7 +20075,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19953,7 +20075,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@note If @ref json_serializer<ValueType> has both overloads of
@note If @ref json_serializer<ValueType> has both overloads of
`from_json()`, this one is chosen.
`from_json()`, this one is chosen.
@tparam ValueTypeCV the provided value type
@tparam ValueType the returned value type
@tparam ValueType the returned value type
@return copy of the JSON value, converted to @a ValueType
@return copy of the JSON value, converted to @a ValueType
...
@@ -19962,134 +20083,116 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -19962,134 +20083,116 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 2.1.0
@since version 2.1.0
*/
*/
template
<
typename
ValueType
CV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
template
<
typename
ValueType
,
detail
::
enable_if_t
<
!
std
::
is_same
<
basic_json_t
,
ValueType
>::
value
&&
detail
::
enable_if_t
<
detail
::
has_non_default_from_json
<
basic_json_t
,
ValueType
>::
value
,
detail
::
has_non_default_from_json
<
basic_json_t
,
ValueType
>::
value
,
int
>
=
0
>
int
>
=
0
>
ValueType
get
(
)
const
noexcept
(
noexcept
(
ValueType
get
_impl
(
detail
::
priority_tag
<
1
>
/*unused*/
)
const
noexcept
(
noexcept
(
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
())))
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
())))
{
{
static_assert
(
!
std
::
is_reference
<
ValueTypeCV
>::
value
,
"get() cannot be used with reference types, you might want to use get_ref()"
);
return
JSONSerializer
<
ValueType
>::
from_json
(
*
this
);
return
JSONSerializer
<
ValueType
>::
from_json
(
*
this
);
}
}
/*!
/*!
@brief get a value (explicit)
@brief get special-case overload
Explicit type conversion between the JSON value and a compatible value.
The value is filled into the input parameter by calling the @ref json_serializer<ValueType>
`from_json()` method.
The function is equivalent to executing
@code {.cpp}
ValueType v;
JSONSerializer<ValueType>::from_json(*this, v);
@endcode
This overloads is chosen if:
- @a ValueType is not @ref basic_json,
- @ref json_serializer<ValueType> has a `from_json()` method of the form
`void from_json(const basic_json&, ValueType&)`, and
@tparam ValueType the input parameter type.
This overloads converts the current @ref basic_json in a different
@ref basic_json type
@
return the input parameter, allowing chaining calls.
@
tparam BasicJsonType == @ref basic_json
@
throw what @ref json_serializer<ValueType> `from_json()` method throws
@
return a copy of *this, converted into @a BasicJsonType
@liveexample{The example below shows several conversions from JSON values
@complexity Depending on the implementation of the called `from_json()`
to other types. There a few things to note: (1) Floating-point numbers can
method.
be converted to integers\, (2) A JSON array can be converted to a standard
`std::vector<short>`\, (3) A JSON object can be converted to C++
associative containers such as `std::unordered_map<std::string\,
json>`.,get_to}
@since version 3.
3
.0
@since version 3.
2
.0
*/
*/
template
<
typename
Value
Type
,
template
<
typename
BasicJson
Type
,
detail
::
enable_if_t
<
detail
::
enable_if_t
<
!
detail
::
is_basic_json
<
ValueType
>::
value
&&
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
,
int
>
=
0
>
int
>
=
0
>
ValueType
&
get_to
(
ValueType
&
v
)
const
noexcept
(
noexcept
(
BasicJsonType
get_impl
(
detail
::
priority_tag
<
2
>
/*unused*/
)
const
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
{
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
v
);
return
*
this
;
return
v
;
}
}
// specialization to allow to call get_to with a basic_json value
/*!
// see https://github.com/nlohmann/json/issues/2175
@brief get special-case overload
template
<
typename
ValueType
,
detail
::
enable_if_t
<
This overloads avoids a lot of template boilerplate, it can be seen as the
detail
::
is_basic_json
<
ValueType
>::
value
,
identity method
@tparam BasicJsonType == @ref basic_json
@return a copy of *this
@complexity Constant.
@since version 2.1.0
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
std
::
is_same
<
BasicJsonType
,
basic_json_t
>::
value
,
int
>
=
0
>
int
>
=
0
>
ValueType
&
get_to
(
ValueType
&
v
)
const
basic_json
get_impl
(
detail
::
priority_tag
<
3
>
/*unused*/
)
const
{
{
v
=
*
this
;
return
*
this
;
return
v
;
}
}
template
<
/*!
typename
T
,
std
::
size_t
N
,
@brief get a pointer value (explicit)
typename
Array
=
T
(
&
)[
N
],
// NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
@copydoc get()
detail
::
enable_if_t
<
*/
detail
::
has_from_json
<
basic_json_t
,
Array
>::
value
,
int
>
=
0
>
template
<
typename
PointerType
,
Array
get_to
(
T
(
&
v
)[
N
])
const
// NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
detail
::
enable_if_t
<
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
std
::
is_pointer
<
PointerType
>::
value
,
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
int
>
=
0
>
constexpr
auto
get_impl
(
detail
::
priority_tag
<
4
>
/*unused*/
)
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
{
{
JSONSerializer
<
Array
>::
from_json
(
*
this
,
v
);
// delegate the call to get_ptr
return
v
;
return
get_ptr
<
PointerType
>
()
;
}
}
public
:
/*!
/*!
@brief get a
pointer value (im
plicit)
@brief get a
(pointer) value (ex
plicit)
Implicit pointer access to the internally stored JSON value. No copies are
Performs explicit type conversion between the JSON value and a compatible value if required.
made.
@warning Writing data to the pointee of the result yields an undefined
- If the requested type is a pointer to the internally stored JSON value that pointer is returned.
stat
e.
No copies are mad
e.
@tparam PointerType pointer type; must be a pointer to @ref array_t, @ref
- If the requested type is the current @ref basic_json, or a different @ref basic_json convertible
object_t, @ref string_t, @ref boolean_t, @ref number_integer_t,
from the current @ref basic_json.
@ref number_unsigned_t, or @ref number_float_t. Enforced by a static
assertion.
@return pointer to the internally stored JSON value if the requested
- Otherwise the value is converted by calling the @ref json_serializer<ValueType> `from_json()`
pointer type @a PointerType fits to the JSON value; `nullptr` otherwise
method.
@complexity Constant.
@tparam ValueTypeCV the provided value type
@tparam ValueType the returned value type
@liveexample{The example below shows how pointers to internal values of a
@return copy of the JSON value, converted to @tparam ValueType if necessary
JSON value can be requested. Note that no type conversions are made and a
`nullptr` is returned if the value and the requested pointer type does not
match.,get_ptr}
@since version 1.0.0
@throw what @ref json_serializer<ValueType> `from_json()` method throws if conversion is required
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
auto
get_ptr
()
noexcept
->
decltype
(
std
::
declval
<
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
// delegate the call to get_impl_ptr<>()
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
}
/*!
@since version 2.1.0
@brief get a pointer value (implicit)
@copydoc get_ptr()
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>>
std
::
is_pointer
<
PointerType
>::
value
&&
#if defined(JSON_HAS_CPP_14)
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
constexpr
constexpr
auto
get_ptr
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
#endif
auto
get
()
const
noexcept
(
noexcept
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_impl
<
ValueType
>
(
detail
::
priority_tag
<
4
>
{})))
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_impl
<
ValueType
>
(
detail
::
priority_tag
<
4
>
{}))
{
{
// delegate the call to get_impl_ptr<>() const
// we cannot static_assert on ValueTypeCV being non-const, because
return
get_impl_ptr
(
static_cast
<
PointerType
>
(
nullptr
));
// there is support for get<const basic_json_t>(), which is why we
// still need the uncvref
static_assert
(
!
std
::
is_reference
<
ValueTypeCV
>::
value
,
"get() cannot be used with reference types, you might want to use get_ref()"
);
return
get_impl
<
ValueType
>
(
detail
::
priority_tag
<
4
>
{});
}
}
/*!
/*!
...
@@ -20128,15 +20231,73 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20128,15 +20231,73 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
}
/*!
/*!
@brief get a pointer value (explicit)
@brief get a value (explicit)
@copydoc get()
Explicit type conversion between the JSON value and a compatible value.
The value is filled into the input parameter by calling the @ref json_serializer<ValueType>
`from_json()` method.
The function is equivalent to executing
@code {.cpp}
ValueType v;
JSONSerializer<ValueType>::from_json(*this, v);
@endcode
This overloads is chosen if:
- @a ValueType is not @ref basic_json,
- @ref json_serializer<ValueType> has a `from_json()` method of the form
`void from_json(const basic_json&, ValueType&)`, and
@tparam ValueType the input parameter type.
@return the input parameter, allowing chaining calls.
@throw what @ref json_serializer<ValueType> `from_json()` method throws
@liveexample{The example below shows several conversions from JSON values
to other types. There a few things to note: (1) Floating-point numbers can
be converted to integers\, (2) A JSON array can be converted to a standard
`std::vector<short>`\, (3) A JSON object can be converted to C++
associative containers such as `std::unordered_map<std::string\,
json>`.,get_to}
@since version 3.3.0
*/
*/
template
<
typename
PointerType
,
typename
std
::
enable_if
<
template
<
typename
ValueType
,
std
::
is_pointer
<
PointerType
>::
value
,
int
>::
type
=
0
>
detail
::
enable_if_t
<
constexpr
auto
get
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
template
get_ptr
<
PointerType
>
())
!
detail
::
is_basic_json
<
ValueType
>::
value
&&
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
,
int
>
=
0
>
ValueType
&
get_to
(
ValueType
&
v
)
const
noexcept
(
noexcept
(
JSONSerializer
<
ValueType
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
{
// delegate the call to get_ptr
JSONSerializer
<
ValueType
>::
from_json
(
*
this
,
v
);
return
get_ptr
<
PointerType
>
();
return
v
;
}
// specialization to allow to call get_to with a basic_json value
// see https://github.com/nlohmann/json/issues/2175
template
<
typename
ValueType
,
detail
::
enable_if_t
<
detail
::
is_basic_json
<
ValueType
>::
value
,
int
>
=
0
>
ValueType
&
get_to
(
ValueType
&
v
)
const
{
v
=
*
this
;
return
v
;
}
template
<
typename
T
,
std
::
size_t
N
,
typename
Array
=
T
(
&
)[
N
],
// NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
detail
::
enable_if_t
<
detail
::
has_from_json
<
basic_json_t
,
Array
>::
value
,
int
>
=
0
>
Array
get_to
(
T
(
&
v
)[
N
])
const
// NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
JSONSerializer
<
Array
>::
from_json
(
*
this
,
v
);
return
v
;
}
}
/*!
/*!
...
@@ -25755,8 +25916,10 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
...
@@ -25755,8 +25916,10 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
#undef JSON_THROW
#undef JSON_THROW
#undef JSON_TRY
#undef JSON_TRY
#undef JSON_PRIVATE_UNLESS_TESTED
#undef JSON_PRIVATE_UNLESS_TESTED
#undef JSON_HAS_CPP_11
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_20
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL
#undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT
#undef JSON_EXPLICIT
...
...
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