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
1ca6f290
Unverified
Commit
1ca6f290
authored
Nov 05, 2019
by
Niels Lohmann
Committed by
GitHub
Nov 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1826 from cbegue/develop
Add restriction for tuple specialization of to_json
parents
abccafa5
8b686b30
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
6 deletions
+38
-6
include/nlohmann/detail/conversions/to_json.hpp
include/nlohmann/detail/conversions/to_json.hpp
+3
-3
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+13
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+16
-3
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+6
-0
No files found.
include/nlohmann/detail/conversions/to_json.hpp
View file @
1ca6f290
...
...
@@ -322,10 +322,10 @@ void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...>
j
=
{
std
::
get
<
Idx
>
(
t
)...
};
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
tuple
<
Args
...
>
&
t
)
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
is_constructible_tuple
<
BasicJsonType
,
T
>
::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
T
&
t
)
{
to_json_tuple_impl
(
j
,
t
,
index_sequence_for
<
Args
...
>
{});
to_json_tuple_impl
(
j
,
t
,
make_index_sequence
<
std
::
tuple_size
<
T
>::
value
>
{});
}
struct
to_json_fn
...
...
include/nlohmann/detail/meta/type_traits.hpp
View file @
1ca6f290
...
...
@@ -357,5 +357,18 @@ struct is_compatible_type_impl <
template
<
typename
BasicJsonType
,
typename
CompatibleType
>
struct
is_compatible_type
:
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
>
struct
is_constructible_tuple
:
std
::
false_type
{};
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
}
// namespace detail
}
// namespace nlohmann
single_include/nlohmann/json.hpp
View file @
1ca6f290
...
...
@@ -2794,6 +2794,19 @@ struct is_compatible_type_impl <
template
<
typename
BasicJsonType
,
typename
CompatibleType
>
struct
is_compatible_type
:
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
>
struct
is_constructible_tuple
:
std
::
false_type
{};
template
<
typename
T1
,
typename
...
Args
>
struct
is_constructible_tuple
<
T1
,
std
::
tuple
<
Args
...
>>
:
conjunction
<
std
::
is_constructible
<
T1
,
Args
>
...
>
{};
}
// namespace detail
}
// namespace nlohmann
...
...
@@ -3753,10 +3766,10 @@ void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...>
j
=
{
std
::
get
<
Idx
>
(
t
)...
};
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
to_json
(
BasicJsonType
&
j
,
const
std
::
tuple
<
Args
...
>
&
t
)
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
is_constructible_tuple
<
BasicJsonType
,
T
>
::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
T
&
t
)
{
to_json_tuple_impl
(
j
,
t
,
index_sequence_for
<
Args
...
>
{});
to_json_tuple_impl
(
j
,
t
,
make_index_sequence
<
std
::
tuple_size
<
T
>::
value
>
{});
}
struct
to_json_fn
...
...
test/src/unit-regression.cpp
View file @
1ca6f290
...
...
@@ -1842,6 +1842,12 @@ TEST_CASE("regression tests")
static_assert
(
!
std
::
is_constructible
<
json
,
std
::
pair
<
NotSerializableData
,
std
::
string
>>::
value
,
""
);
static_assert
(
std
::
is_constructible
<
json
,
std
::
pair
<
int
,
std
::
string
>>::
value
,
""
);
}
SECTION
(
"issue #1825 - A tuple<Args..> is json constructible only if all T in Args are json constructible"
)
{
static_assert
(
!
std
::
is_constructible
<
json
,
std
::
tuple
<
std
::
string
,
NotSerializableData
>>::
value
,
""
);
static_assert
(
!
std
::
is_constructible
<
json
,
std
::
tuple
<
NotSerializableData
,
std
::
string
>>::
value
,
""
);
static_assert
(
std
::
is_constructible
<
json
,
std
::
tuple
<
int
,
std
::
string
>>::
value
,
""
);
}
}
#if not defined(JSON_NOEXCEPTION)
...
...
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