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
5b71bf09
Commit
5b71bf09
authored
Aug 24, 2017
by
Niels Lohmann
Committed by
GitHub
Aug 24, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #708 from theodelrieu/fix/from_json_tuple_pair
fix from_json implementation for pair/tuple
parents
e45eaf6e
bb1b4c93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
src/json.hpp
src/json.hpp
+4
-4
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+3
-1
No files found.
src/json.hpp
View file @
5b71bf09
...
...
@@ -1235,16 +1235,16 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
}
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
void
from_json
(
const
BasicJsonType
&
j
,
std
::
pair
<
A
rgs
...
>&
p
)
template
<
typename
BasicJsonType
,
typename
A1
,
typename
A2
>
void
from_json
(
const
BasicJsonType
&
j
,
std
::
pair
<
A
1
,
A2
>&
p
)
{
p
=
{
j
.
at
(
0
)
,
j
.
at
(
1
)};
p
=
{
j
.
at
(
0
)
.
template
get
<
A1
>(),
j
.
at
(
1
).
template
get
<
A2
>(
)};
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
void
from_json_tuple_impl
(
const
BasicJsonType
&
j
,
Tuple
&
t
,
index_sequence
<
Idx
...
>
)
{
t
=
std
::
make_tuple
(
j
.
at
(
Idx
)...);
t
=
std
::
make_tuple
(
j
.
at
(
Idx
).
template
get
<
typename
std
::
tuple_element
<
Idx
,
Tuple
>
::
type
>
().
..);
}
template
<
typename
BasicJsonType
,
typename
...
Args
>
...
...
test/src/unit-constructor1.cpp
View file @
5b71bf09
...
...
@@ -246,6 +246,7 @@ TEST_CASE("constructors")
json
j
(
p
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
CHECK
(
j
.
get
<
decltype
(
p
)
>
()
==
p
);
REQUIRE
(
j
.
size
()
==
2
);
CHECK
(
j
[
0
]
==
std
::
get
<
0
>
(
p
));
CHECK
(
j
[
1
]
==
std
::
get
<
1
>
(
p
));
...
...
@@ -262,11 +263,12 @@ TEST_CASE("constructors")
SECTION
(
"std::tuple"
)
{
const
auto
t
=
std
::
make_tuple
(
1.0
,
"string"
,
42
,
std
::
vector
<
int
>
{
0
,
1
});
const
auto
t
=
std
::
make_tuple
(
1.0
,
std
::
string
{
"string"
}
,
42
,
std
::
vector
<
int
>
{
0
,
1
});
json
j
(
t
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
REQUIRE
(
j
.
size
()
==
4
);
CHECK
(
j
.
get
<
decltype
(
t
)
>
()
==
t
);
CHECK
(
j
[
0
]
==
std
::
get
<
0
>
(
t
));
CHECK
(
j
[
1
]
==
std
::
get
<
1
>
(
t
));
CHECK
(
j
[
2
]
==
std
::
get
<
2
>
(
t
));
...
...
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