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
20b5f4d8
Unverified
Commit
20b5f4d8
authored
Feb 12, 2018
by
Niels Lohmann
Committed by
GitHub
Feb 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #969 from theodelrieu/fix/924
Fix constraints on from_json(CompatibleArrayType)
parents
b02e3bb0
01d61188
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
12 deletions
+46
-12
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+11
-5
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+11
-5
test/src/unit-inspection.cpp
test/src/unit-inspection.cpp
+2
-2
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+22
-0
No files found.
include/nlohmann/detail/conversions/from_json.hpp
View file @
20b5f4d8
...
...
@@ -177,15 +177,21 @@ void from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priorit
}
}
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
not
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>
::
value
and
not
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
and
std
::
is_constructible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
,
int
>
=
0
>
void
from_json
(
const
BasicJsonType
&
j
,
CompatibleArrayType
&
arr
)
{
if
(
JSON_UNLIKELY
(
not
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
2
>
{});
...
...
single_include/nlohmann/json.hpp
View file @
20b5f4d8
...
...
@@ -1084,15 +1084,21 @@ void from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priorit
}
}
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
not
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
template
<
typename
BasicJsonType
,
typename
CompatibleArrayType
,
enable_if_t
<
is_compatible_array_type
<
BasicJsonType
,
CompatibleArrayType
>
::
value
and
not
std
::
is_same
<
typename
BasicJsonType
::
array_t
,
CompatibleArrayType
>::
value
and
std
::
is_constructible
<
BasicJsonType
,
typename
CompatibleArrayType
::
value_type
>::
value
,
int
>
=
0
>
void
from_json
(
const
BasicJsonType
&
j
,
CompatibleArrayType
&
arr
)
{
if
(
JSON_UNLIKELY
(
not
j
.
is_array
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
JSON_THROW
(
type_error
::
create
(
302
,
"type must be array, but is "
+
std
::
string
(
j
.
type_name
())));
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
2
>
{});
...
...
test/src/unit-inspection.cpp
View file @
20b5f4d8
...
...
@@ -316,8 +316,8 @@ TEST_CASE("object inspection")
SECTION
(
"round trips"
)
{
for
(
const
auto
&
s
:
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
json
j1
=
json
::
parse
(
s
);
std
::
string
s1
=
j1
.
dump
();
...
...
test/src/unit-udt.cpp
View file @
20b5f4d8
...
...
@@ -711,3 +711,25 @@ TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated
{
static_assert
(
not
is_constructible_patched
<
json
,
incomplete
>::
value
,
""
);
}
namespace
{
class
Evil
{
public:
Evil
()
=
default
;
template
<
typename
T
>
Evil
(
T
)
{}
};
void
from_json
(
const
json
&
,
Evil
&
)
{}
}
TEST_CASE
(
"Issue #924"
)
{
// Prevent get<std::vector<Evil>>() to throw
auto
j
=
json
::
array
();
(
void
)
j
.
get
<
Evil
>
();
(
void
)
j
.
get
<
std
::
vector
<
Evil
>>
();
}
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