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
a9d5ae4f
Commit
a9d5ae4f
authored
Jan 14, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put back a specialization for containers with a reserve method
parent
e247e01a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
src/json.hpp
src/json.hpp
+36
-10
No files found.
src/json.hpp
View file @
a9d5ae4f
...
...
@@ -642,6 +642,41 @@ void from_json(Json const&j, std::forward_list<T, Allocator>& l)
l
.
push_front
(
it
->
template
get
<
T
>());
}
template
<
typename
Json
,
typename
CompatibleArrayType
>
void
from_json_array_impl
(
Json
const
&
j
,
CompatibleArrayType
&
arr
,
long
)
{
using
std
::
begin
;
using
std
::
end
;
std
::
transform
(
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
Json
const
&
i
)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return
i
.
template
get
<
typename
CompatibleArrayType
::
value_type
>();
});
}
template
<
typename
Json
,
typename
CompatibleArrayType
>
auto
from_json_array_impl
(
Json
const
&
j
,
CompatibleArrayType
&
arr
,
int
)
->
decltype
(
arr
.
reserve
(
std
::
declval
<
typename
CompatibleArrayType
::
size_type
>
()),
void
())
{
using
std
::
begin
;
using
std
::
end
;
arr
.
reserve
(
j
.
size
());
std
::
transform
(
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
Json
const
&
i
)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return
i
.
template
get
<
typename
CompatibleArrayType
::
value_type
>();
});
}
template
<
typename
Json
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
Json
,
CompatibleArrayType
>
::
value
and
...
...
@@ -658,16 +693,7 @@ void from_json(Json const &j, CompatibleArrayType &arr)
if
(
!
j
.
is_array
())
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
using
std
::
begin
;
using
std
::
end
;
std
::
transform
(
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
Json
const
&
i
)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
return
i
.
template
get
<
typename
CompatibleArrayType
::
value_type
>();
});
from_json_array_impl
(
j
,
arr
,
0
);
}
...
...
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