Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
23f462b5
Commit
23f462b5
authored
Jan 10, 2021
by
Anthony VH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduced code duplication, renamed tag to identity_tag.
parent
1b113f73
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
114 deletions
+99
-114
include/nlohmann/adl_serializer.hpp
include/nlohmann/adl_serializer.hpp
+4
-3
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+44
-53
include/nlohmann/detail/meta/identity_tag.hpp
include/nlohmann/detail/meta/identity_tag.hpp
+1
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+50
-57
No files found.
include/nlohmann/adl_serializer.hpp
View file @
23f462b5
...
...
@@ -5,6 +5,7 @@
#include <nlohmann/detail/conversions/from_json.hpp>
#include <nlohmann/detail/conversions/to_json.hpp>
#include <nlohmann/detail/meta/identity_tag.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
namespace
nlohmann
...
...
@@ -46,10 +47,10 @@ struct adl_serializer
*/
template
<
typename
BasicJsonType
,
typename
TargetType
=
ValueType
>
static
auto
from_json
(
BasicJsonType
&&
j
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
tag
<
TargetType
>
{})))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
tag
<
TargetType
>
{}))
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
::
tag
<
TargetType
>
{});
return
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
identity_
tag
<
TargetType
>
{});
}
/*!
...
...
include/nlohmann/detail/conversions/from_json.hpp
View file @
23f462b5
...
...
@@ -15,7 +15,7 @@
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/tag.hpp>
#include <nlohmann/detail/meta/
identity_
tag.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>
...
...
@@ -250,16 +250,16 @@ void())
}
template
<
typename
BasicJsonType
,
typename
Array
,
std
::
size_t
...
Is
>
Array
from_json_array_impl
(
BasicJsonType
&&
j
,
tag
<
Array
>
/*unused*/
,
index_sequence
<
Is
...
>
/*unused*/
)
Array
from_json_array_impl
(
BasicJsonType
&&
j
,
identity_
tag
<
Array
>
/*unused*/
,
index_sequence
<
Is
...
>
/*unused*/
)
{
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Is
).
template
get
<
typename
Array
::
value_type
>()...
};
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
array
<
T
,
N
>
>::
value
,
int
>
=
0
>
auto
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
array
<
T
,
N
>>
t
)
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
N
>>
tag
)
->
decltype
(
j
.
template
get
<
T
>(),
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
make_index_sequence
<
N
>
{}))
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
ag
,
make_index_sequence
<
N
>
{}))
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -267,7 +267,7 @@ from_json_array_impl(std::forward<BasicJsonType>(j), t, make_index_sequence<N> {
std
::
string
(
j
.
type_name
())));
}
return
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
make_index_sequence
<
N
>
{});
return
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
ag
,
make_index_sequence
<
N
>
{});
}
template
<
typename
BasicJsonType
>
...
...
@@ -345,24 +345,24 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
}
}
template
<
typename
BasicJsonType
,
class
A1
,
class
A2
>
std
::
pair
<
A1
,
A2
>
from_json_pair_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
,
enable_if_t
<
std
::
is_default_constructible
<
std
::
pair
<
A1
,
A2
>
>::
value
,
int
>
=
0
>
void
from_json
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
)
void
from_json
_pair_impl
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
,
priority_tag
<
1
>
/*unused*/
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
p
=
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
0
).
template
get
<
A1
>(),
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>()
};
p
=
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
std
::
pair
<
A1
,
A2
>>
{},
priority_tag
<
0
>
{});
}
template
<
typename
BasicJsonType
,
class
A1
,
class
A2
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
pair
<
A1
,
A2
>
>::
value
,
int
>
=
0
>
std
::
pair
<
A1
,
A2
>
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
pair
<
A1
,
A2
>>
/*unused*/
)
template
<
typename
BasicJsonType
,
typename
PairRelatedType
>
auto
from_json
(
BasicJsonType
&&
j
,
PairRelatedType
&&
p
)
->
decltype
(
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
PairRelatedType
>
(
p
),
priority_tag
<
1
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -370,19 +370,25 @@ std::pair<A1, A2> from_json(BasicJsonType && j, tag<std::pair<A1, A2>> /*unused*
std
::
string
(
j
.
type_name
())));
}
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
0
).
template
get
<
A1
>(),
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>()};
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
>
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
)
Tuple
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
Tuple
>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
{
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...);
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
,
enable_if_t
<
std
::
is_default_constructible
<
Tuple
>
::
value
,
int
>
=
0
>
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
1
>
/*unused*/
)
{
t
=
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...
);
t
=
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
Tuple
>
{},
priority_tag
<
0
>
{}
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
,
enable_if_t
<
std
::
is_default_constructible
<
std
::
tuple
<
Args
...>
>::
value
,
int
>
=
0
>
void
from_json
(
BasicJsonType
&&
j
,
std
::
tuple
<
Args
...
>&
t
)
template
<
typename
BasicJsonType
,
typename
TupleRelated
,
std
::
size_t
...
Idx
>
auto
from_json_tuple
(
BasicJsonType
&&
j
,
TupleRelated
&&
t
,
index_sequence
<
Idx
...
>
idx
)
->
decltype
(
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -390,26 +396,21 @@ void from_json(BasicJsonType && j, std::tuple<Args...>& t)
std
::
string
(
j
.
type_name
())));
}
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{});
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{});
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
Tuple
from_json_tuple_impl
(
BasicJsonType
&&
j
,
tag
<
Tuple
>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
)
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
...
>
{}))
{
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...
);
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{}
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
tuple
<
Args
...>
>::
value
,
int
>
=
0
>
std
::
tuple
<
Args
...
>
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
tuple
<
Args
...
>>
t
)
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
...
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
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
,
...
...
@@ -455,21 +456,11 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
struct
from_json_fn
{
template
<
typename
BasicJsonType
,
typename
T
>
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
->
decltype
(
from_json
(
j
,
val
),
void
())
{
return
from_json
(
j
,
val
);
}
// overload to pass calls to built-in from_json functions for non-default constructible STL
// types (e.g. std::array<X>, where X is not default constructible).
template
<
typename
BasicJsonType
,
typename
T
>
auto
operator
()(
const
BasicJsonType
&
j
,
detail
::
tag
<
T
>
t
)
const
noexcept
(
noexcept
(
from_json
(
j
,
t
)))
->
decltype
(
from_json
(
j
,
t
))
auto
operator
()(
const
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
)))
{
return
from_json
(
j
,
t
);
return
from_json
(
j
,
std
::
forward
<
T
>
(
val
)
);
}
};
}
// namespace detail
...
...
include/nlohmann/detail/meta/tag.hpp
→
include/nlohmann/detail/meta/
identity_
tag.hpp
View file @
23f462b5
...
...
@@ -5,6 +5,6 @@ namespace nlohmann
namespace
detail
{
// dispatching helper struct
template
<
class
T
>
struct
tag
{};
template
<
class
T
>
struct
identity_
tag
{};
}
// namespace detail
}
// namespace nlohmann
single_include/nlohmann/json.hpp
View file @
23f462b5
...
...
@@ -2813,7 +2813,7 @@ constexpr T static_const<T>::value;
}
// namespace detail
}
// namespace nlohmann
// #include <nlohmann/detail/meta/tag.hpp>
// #include <nlohmann/detail/meta/
identity_
tag.hpp>
namespace
nlohmann
...
...
@@ -2821,7 +2821,7 @@ namespace nlohmann
namespace
detail
{
// dispatching helper struct
template
<
class
T
>
struct
tag
{};
template
<
class
T
>
struct
identity_
tag
{};
}
// namespace detail
}
// namespace nlohmann
...
...
@@ -3747,16 +3747,16 @@ void())
}
template
<
typename
BasicJsonType
,
typename
Array
,
std
::
size_t
...
Is
>
Array
from_json_array_impl
(
BasicJsonType
&&
j
,
tag
<
Array
>
/*unused*/
,
index_sequence
<
Is
...
>
/*unused*/
)
Array
from_json_array_impl
(
BasicJsonType
&&
j
,
identity_
tag
<
Array
>
/*unused*/
,
index_sequence
<
Is
...
>
/*unused*/
)
{
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Is
).
template
get
<
typename
Array
::
value_type
>()...
};
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
array
<
T
,
N
>
>::
value
,
int
>
=
0
>
auto
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
array
<
T
,
N
>>
t
)
auto
from_json
(
BasicJsonType
&&
j
,
identity_tag
<
std
::
array
<
T
,
N
>>
tag
)
->
decltype
(
j
.
template
get
<
T
>(),
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
make_index_sequence
<
N
>
{}))
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
ag
,
make_index_sequence
<
N
>
{}))
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -3764,7 +3764,7 @@ from_json_array_impl(std::forward<BasicJsonType>(j), t, make_index_sequence<N> {
std
::
string
(
j
.
type_name
())));
}
return
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
make_index_sequence
<
N
>
{});
return
from_json_array_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
ag
,
make_index_sequence
<
N
>
{});
}
template
<
typename
BasicJsonType
>
...
...
@@ -3842,24 +3842,24 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
}
}
template
<
typename
BasicJsonType
,
class
A1
,
class
A2
>
std
::
pair
<
A1
,
A2
>
from_json_pair_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
,
enable_if_t
<
std
::
is_default_constructible
<
std
::
pair
<
A1
,
A2
>
>::
value
,
int
>
=
0
>
void
from_json
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
)
void
from_json
_pair_impl
(
BasicJsonType
&&
j
,
std
::
pair
<
A1
,
A2
>&
p
,
priority_tag
<
1
>
/*unused*/
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
p
=
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
0
).
template
get
<
A1
>(),
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>()
};
p
=
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
std
::
pair
<
A1
,
A2
>>
{},
priority_tag
<
0
>
{});
}
template
<
typename
BasicJsonType
,
class
A1
,
class
A2
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
pair
<
A1
,
A2
>
>::
value
,
int
>
=
0
>
std
::
pair
<
A1
,
A2
>
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
pair
<
A1
,
A2
>>
/*unused*/
)
template
<
typename
BasicJsonType
,
typename
PairRelatedType
>
auto
from_json
(
BasicJsonType
&&
j
,
PairRelatedType
&&
p
)
->
decltype
(
from_json_pair_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
PairRelatedType
>
(
p
),
priority_tag
<
1
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -3867,19 +3867,25 @@ std::pair<A1, A2> from_json(BasicJsonType && j, tag<std::pair<A1, A2>> /*unused*
std
::
string
(
j
.
type_name
())));
}
return
{
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
0
).
template
get
<
A1
>(),
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
1
).
template
get
<
A2
>()};
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
>
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
)
Tuple
from_json_tuple_impl
(
BasicJsonType
&&
j
,
identity_tag
<
Tuple
>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
{
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...);
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
,
enable_if_t
<
std
::
is_default_constructible
<
Tuple
>
::
value
,
int
>
=
0
>
void
from_json_tuple_impl
(
BasicJsonType
&&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
/*unused*/
,
priority_tag
<
1
>
/*unused*/
)
{
t
=
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...
);
t
=
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
identity_tag
<
Tuple
>
{},
priority_tag
<
0
>
{}
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
,
enable_if_t
<
std
::
is_default_constructible
<
std
::
tuple
<
Args
...>
>::
value
,
int
>
=
0
>
void
from_json
(
BasicJsonType
&&
j
,
std
::
tuple
<
Args
...
>&
t
)
template
<
typename
BasicJsonType
,
typename
TupleRelated
,
std
::
size_t
...
Idx
>
auto
from_json_tuple
(
BasicJsonType
&&
j
,
TupleRelated
&&
t
,
index_sequence
<
Idx
...
>
idx
)
->
decltype
(
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
...
...
@@ -3887,26 +3893,21 @@ void from_json(BasicJsonType && j, std::tuple<Args...>& t)
std
::
string
(
j
.
type_name
())));
}
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{});
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
std
::
forward
<
TupleRelated
>
(
t
),
idx
,
priority_tag
<
1
>
{});
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
Tuple
from_json_tuple_impl
(
BasicJsonType
&&
j
,
tag
<
Tuple
>
/*unused*/
,
index_sequence
<
Idx
...
>
/*unused*/
)
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
...
>
{}))
{
return
std
::
make_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
).
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
()...
);
from_json_tuple
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
index_sequence_for
<
Args
...
>
{}
);
}
template
<
typename
BasicJsonType
,
typename
...
Args
,
enable_if_t
<
!
std
::
is_default_constructible
<
std
::
tuple
<
Args
...>
>::
value
,
int
>
=
0
>
std
::
tuple
<
Args
...
>
from_json
(
BasicJsonType
&&
j
,
tag
<
std
::
tuple
<
Args
...
>>
t
)
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
...
>
{})
)
{
if
(
JSON_HEDLEY_UNLIKELY
(
!
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
return
from_json_tuple_impl
(
std
::
forward
<
BasicJsonType
>
(
j
),
t
,
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
,
...
...
@@ -3952,21 +3953,11 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
struct
from_json_fn
{
template
<
typename
BasicJsonType
,
typename
T
>
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
->
decltype
(
from_json
(
j
,
val
),
void
())
{
return
from_json
(
j
,
val
);
}
// overload to pass calls to built-in from_json functions for non-default constructible STL
// types (e.g. std::array<X>, where X is not default constructible).
template
<
typename
BasicJsonType
,
typename
T
>
auto
operator
()(
const
BasicJsonType
&
j
,
detail
::
tag
<
T
>
t
)
const
noexcept
(
noexcept
(
from_json
(
j
,
t
)))
->
decltype
(
from_json
(
j
,
t
))
auto
operator
()(
const
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
from_json
(
j
,
std
::
forward
<
T
>
(
val
)))
{
return
from_json
(
j
,
t
);
return
from_json
(
j
,
std
::
forward
<
T
>
(
val
)
);
}
};
}
// namespace detail
...
...
@@ -4540,6 +4531,8 @@ constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
}
// namespace
}
// namespace nlohmann
// #include <nlohmann/detail/meta/identity_tag.hpp>
// #include <nlohmann/detail/meta/type_traits.hpp>
...
...
@@ -4582,10 +4575,10 @@ struct adl_serializer
*/
template
<
typename
BasicJsonType
,
typename
TargetType
=
ValueType
>
static
auto
from_json
(
BasicJsonType
&&
j
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
tag
<
TargetType
>
{})))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
tag
<
TargetType
>
{}))
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
::
tag
<
TargetType
>
{});
return
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
detail
::
identity_
tag
<
TargetType
>
{});
}
/*!
...
...
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