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
fc8c5842
Commit
fc8c5842
authored
Jan 12, 2021
by
Anthony VH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Regenerated single include.
parent
6ef1614f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
245 additions
and
197 deletions
+245
-197
json.hpp
single_include/nlohmann/json.hpp
+245
-197
No files found.
single_include/nlohmann/json.hpp
View file @
fc8c5842
...
@@ -3185,6 +3185,52 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
...
@@ -3185,6 +3185,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.
// Based on commit fixing this in gcc: https://github.com/gcc-mirror/gcc/commit/d3c64041b32b6962ad6b2d879231537a477631fb
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
{};
...
@@ -3228,9 +3274,9 @@ struct is_compatible_object_type_impl <
...
@@ -3228,9 +3274,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
;
};
};
...
@@ -3251,10 +3297,10 @@ struct is_constructible_object_type_impl <
...
@@ -3251,10 +3297,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
,
...
@@ -3282,7 +3328,7 @@ struct is_compatible_string_type_impl <
...
@@ -3282,7 +3328,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
>
...
@@ -3300,7 +3346,7 @@ struct is_constructible_string_type_impl <
...
@@ -3300,7 +3346,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
;
};
};
...
@@ -3323,7 +3369,7 @@ struct is_compatible_array_type_impl <
...
@@ -3323,7 +3369,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
;
};
};
...
@@ -3346,7 +3392,7 @@ struct is_constructible_array_type_impl <
...
@@ -3346,7 +3392,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
&&
...
@@ -3390,7 +3436,7 @@ struct is_compatible_integer_type_impl <
...
@@ -3390,7 +3436,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
;
...
@@ -3417,18 +3463,11 @@ template<typename BasicJsonType, typename CompatibleType>
...
@@ -3417,18 +3463,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
>
...
>
{};
}
// namespace detail
}
// namespace detail
}
// namespace nlohmann
}
// namespace nlohmann
...
@@ -3746,23 +3785,16 @@ void())
...
@@ -3746,23 +3785,16 @@ void())
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{});
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{});
}
}
template
<
typename
T
,
typename
BasicJsonType
,
typename
ArrayType
,
std
::
size_t
...
Idx
>
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
...
Idx
>
ArrayType
from_json_inplace_array_impl_base
(
BasicJsonType
&&
j
,
identity_tag
<
ArrayType
>
/*unused*/
,
std
::
array
<
T
,
sizeof
...(
Idx
)
>
from_json_inplace_array_impl
(
BasicJsonType
&&
j
,
index_sequence
<
Idx
...
>
/*unused*/
)
i
dentity_tag
<
std
::
array
<
T
,
sizeof
...(
Idx
)
>>
/*unused*/
,
i
ndex_sequence
<
Idx
...
>
/*unused*/
)
{
{
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
T
>
()...
};
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
T
>
()...
};
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
auto
from_json_inplace_array_impl
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
N
>>
tag
,
priority_tag
<
0
>
/*unused*/
)
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
N
>>
tag
)
->
decltype
(
from_json_inplace_array_impl_base
<
T
>
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{}))
->
decltype
(
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{}))
{
return
from_json_inplace_array_impl_base
<
T
>
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{});
}
template
<
typename
BasicJsonType
,
typename
ArrayType
>
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
ArrayType
>
tag
)
->
decltype
(
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
priority_tag
<
0
>
{}))
{
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
{
...
@@ -3770,7 +3802,7 @@ auto from_json(BasicJsonType&& j, identity_tag<ArrayType> tag)
...
@@ -3770,7 +3802,7 @@ auto from_json(BasicJsonType&& j, identity_tag<ArrayType> tag)
std
::
string
(
j
.
type_name
())));
std
::
string
(
j
.
type_name
())));
}
}
return
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
priority_tag
<
0
>
{});
return
from_json_inplace_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
tag
,
make_index_sequence
<
N
>
{});
}
}
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
>
...
@@ -3855,9 +3887,8 @@ std::pair<A1, A2> from_json_pair_impl(BasicJsonType&& j, identity_tag<std::pair<
...
@@ -3855,9 +3887,8 @@ std::pair<A1, A2> from_json_pair_impl(BasicJsonType&& j, identity_tag<std::pair<
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>
()};
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>
()};
}
}
template
<
typename
BasicJsonType
,
typename
A1
,
typename
A2
,
template
<
typename
BasicJsonType
,
typename
A1
,
typename
A2
>
enable_if_t
<
std
::
is_default_constructible
<
std
::
pair
<
A1
,
A2
>>::
value
,
int
>
=
0
>
void
from_json_pair_impl
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
,
priority_tag
<
1
>
/*unused*/
)
void
from_json_pair_impl
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
,
priority_tag
<
1
>
/*unused*/
)
{
{
p
=
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
std
::
pair
<
A1
,
A2
>>
{},
priority_tag
<
0
>
{});
p
=
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
std
::
pair
<
A1
,
A2
>>
{},
priority_tag
<
0
>
{});
}
}
...
@@ -3875,22 +3906,27 @@ auto from_json(BasicJsonType&& j, PairRelatedType&& p)
...
@@ -3875,22 +3906,27 @@ auto from_json(BasicJsonType&& j, PairRelatedType&& p)
return
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
PairRelatedType
>
(
p
),
priority_tag
<
1
>
{});
return
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
PairRelatedType
>
(
p
),
priority_tag
<
1
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
template
<
typename
BasicJsonType
,
typename
...
Args
,
std
::
size_t
...
Idx
>
Tuple
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
Tuple
>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
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
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>::
type
>
()...);
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
Args
>
()...);
}
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
,
template
<
typename
BasicJsonType
,
typename
...
Args
>
enable_if_t
<
std
::
is_default_constructible
<
Tuple
>::
value
,
int
>
=
0
>
std
::
tuple
<
Args
...
>
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
tuple
<
Args
...
>>
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
1
>
/*unused*/
)
{
{
t
=
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
Tuple
>
{},
priority_tag
<
0
>
{});
return
from_json_tuple_impl_base
<
BasicJsonType
,
Args
...
>
(
std
::
forward
<
BasicJsonType
>
(
j
),
index_sequence_for
<
Args
...
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
TupleRelated
,
std
::
size_t
...
Idx
>
template
<
typename
BasicJsonType
,
typename
...
Args
>
auto
from_json_tuple
(
BasicJsonType
&&
j
,
TupleRelated
&&
t
,
index_sequence
<
Idx
...
>
idx
)
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
std
::
tuple
<
Args
...
>&
t
,
priority_tag
<
1
>
/*unused*/
)
->
decltype
(
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{}))
{
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
<
1
>
{}))
{
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
{
...
@@ -3898,21 +3934,7 @@ auto from_json_tuple(BasicJsonType&& j, TupleRelated&& t, index_sequence<Idx...>
...
@@ -3898,21 +3934,7 @@ auto from_json_tuple(BasicJsonType&& j, TupleRelated&& t, index_sequence<Idx...>
std
::
string
(
j
.
type_name
())));
std
::
string
(
j
.
type_name
())));
}
}
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{});
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
priority_tag
<
1
>
{});
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
auto
from_json
(
BasicJsonType
&&
j
,
std
::
tuple
<
Args
...
>&
t
)
->
decltype
(
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{}))
{
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{});
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
tuple
<
Args
...
>>
tag
)
->
decltype
(
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
move
(
tag
),
index_sequence_for
<
Args
...
>
{}))
{
return
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
move
(
tag
),
index_sequence_for
<
Args
...
>
{});
}
}
template
<
typename
BasicJsonType
,
typename
Key
,
typename
Value
,
typename
Compare
,
typename
Allocator
,
template
<
typename
BasicJsonType
,
typename
Key
,
typename
Value
,
typename
Compare
,
typename
Allocator
,
...
@@ -19575,50 +19597,53 @@ class basic_json
...
@@ -19575,50 +19597,53 @@ class basic_json
/// @{
/// @{
/*!
/*!
@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 @tparam 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)
...
@@ -19660,21 +19685,12 @@ class basic_json
...
@@ -19660,21 +19685,12 @@ class basic_json
*/
*/
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
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
;
...
@@ -19712,133 +19728,107 @@ class basic_json
...
@@ -19712,133 +19728,107 @@ class basic_json
@since version 2.1.0
@since version 2.1.0
*/
*/
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>
,
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 @tparam 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
ValueType
,
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
detail
::
enable_if_t
<
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
!
detail
::
is_basic_json
<
ValueType
>::
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
],
@copydoc get()
detail
::
enable_if_t
<
*/
detail
::
has_from_json
<
basic_json_t
,
Array
>::
value
,
int
>
=
0
>
template
<
typename
PointerType
,
detail
::
enable_if_t
<
Array
get_to
(
T
(
&
v
)[
N
])
const
std
::
is_pointer
<
PointerType
>::
value
,
int
>
=
0
>
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
constexpr
auto
get_impl
(
detail
::
priority_tag
<
4
>
/*unused*/
)
const
noexcept
std
::
declval
<
const
basic_json_t
&>
(),
v
)
))
->
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
&&
constexpr
auto
get
()
const
noexcept
(
noexcept
(
get_impl
<
ValueType
>
(
detail
::
priority_tag
<
4
>
{})))
std
::
is_const
<
typename
std
::
remove_pointer
<
PointerType
>::
type
>::
value
,
int
>::
type
=
0
>
->
decltype
(
get_impl
<
ValueType
>
(
detail
::
priority_tag
<
4
>
{}))
constexpr
auto
get_ptr
()
const
noexcept
->
decltype
(
std
::
declval
<
const
basic_json_t
&>
().
get_impl_ptr
(
std
::
declval
<
PointerType
>
()))
{
{
// 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
>
{});
}
}
/*!
/*!
...
@@ -19877,15 +19867,73 @@ class basic_json
...
@@ -19877,15 +19867,73 @@ class basic_json
}
}
/*!
/*!
@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
],
detail
::
enable_if_t
<
detail
::
has_from_json
<
basic_json_t
,
Array
>::
value
,
int
>
=
0
>
Array
get_to
(
T
(
&
v
)[
N
])
const
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
JSONSerializer
<
Array
>::
from_json
(
*
this
,
v
);
return
v
;
}
}
/*!
/*!
...
...
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