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
08d78105
Unverified
Commit
08d78105
authored
Jun 19, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add from_json support for std::array
parent
6e4910d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
src/json.hpp
src/json.hpp
+10
-1
test/src/unit-constructor1.cpp
test/src/unit-constructor1.cpp
+6
-2
No files found.
src/json.hpp
View file @
08d78105
...
...
@@ -1063,6 +1063,15 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio
});
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
std
::
array
<
T
,
N
>&
arr
,
priority_tag
<
2
>
)
{
for
(
std
::
size_t
i
=
0
;
i
<
N
;
++
i
)
{
arr
[
i
]
=
j
.
at
(
i
).
template
get
<
T
>();
}
}
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>
::
value
and
std
::
is_convertible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
and
...
...
@@ -1074,7 +1083,7 @@ void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
j
.
type_name
()));
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
1
>
{});
from_json_array_impl
(
j
,
arr
,
priority_tag
<
2
>
{});
}
template
<
typename
BasicJsonType
,
typename
CompatibleObjectType
,
...
...
test/src/unit-constructor1.cpp
View file @
08d78105
...
...
@@ -283,12 +283,13 @@ TEST_CASE("constructors")
CHECK
(
std
::
get
<
2
>
(
t
)
==
j
[
2
]);
}
SECTION
(
"std::pair/tuple failures"
)
SECTION
(
"std::pair/tuple
/array
failures"
)
{
json
j
{
1
};
CHECK_THROWS
((
j
.
get
<
std
::
pair
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
tuple
<
int
,
int
>>
()));
CHECK_THROWS
((
j
.
get
<
std
::
array
<
int
,
3
>>
()));
}
SECTION
(
"std::forward_list<json>"
)
...
...
@@ -299,12 +300,15 @@ TEST_CASE("constructors")
CHECK
(
j
==
j_reference
);
}
SECTION
(
"std::array<json,
5
>"
)
SECTION
(
"std::array<json,
6
>"
)
{
std
::
array
<
json
,
6
>
a
{{
json
(
1
),
json
(
1u
),
json
(
2.2
),
json
(
false
),
json
(
"string"
),
json
()}};
json
j
(
a
);
CHECK
(
j
.
type
()
==
json
::
value_t
::
array
);
CHECK
(
j
==
j_reference
);
const
auto
a2
=
j
.
get
<
std
::
array
<
json
,
6
>>
();
CHECK
(
a2
==
a
);
}
SECTION
(
"std::vector<json>"
)
...
...
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