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
4b4bbcee
Unverified
Commit
4b4bbcee
authored
Sep 06, 2018
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make from_json SFINAE-correct
parent
f7971f04
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
56 deletions
+16
-56
include/nlohmann/adl_serializer.hpp
include/nlohmann/adl_serializer.hpp
+4
-2
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+3
-25
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+7
-27
test/src/unit-inspection.cpp
test/src/unit-inspection.cpp
+2
-2
No files found.
include/nlohmann/adl_serializer.hpp
View file @
4b4bbcee
...
...
@@ -20,8 +20,10 @@ struct adl_serializer
@param[in,out] val value to write to
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
void
from_json
(
BasicJsonType
&&
j
,
ValueType
&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
static
auto
from_json
(
BasicJsonType
&&
j
,
ValueType
&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
),
void
()
)
{
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
);
}
...
...
include/nlohmann/detail/conversions/from_json.hpp
View file @
4b4bbcee
...
...
@@ -218,8 +218,8 @@ template <typename BasicJsonType, typename CompatibleArrayType,
auto
from_json
(
const
BasicJsonType
&
j
,
CompatibleArrayType
&
arr
)
->
decltype
(
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{}),
j
.
template
get
<
typename
CompatibleArrayType
::
value_type
>(),
void
())
j
.
template
get
<
typename
CompatibleArrayType
::
value_type
>(),
void
())
{
if
(
JSON_UNLIKELY
(
not
j
.
is_array
()))
{
...
...
@@ -350,35 +350,13 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
struct
from_json_fn
{
private:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
const
BasicJsonType
&
j
,
T
&
val
,
priority_tag
<
1
>
/*unused*/
)
const
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
->
decltype
(
from_json
(
j
,
val
),
void
())
{
return
from_json
(
j
,
val
);
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
const
BasicJsonType
&
/*unused*/
,
T
&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find from_json() method in T's namespace"
);
#ifdef _MSC_VER
// MSVC does not show a stacktrace for the above assert
using
decayed
=
uncvref_t
<
T
>
;
static_assert
(
sizeof
(
typename
decayed
::
force_msvc_stacktrace
)
==
0
,
"forcing MSVC stacktrace to show which T we're talking about."
);
#endif
}
public:
template
<
typename
BasicJsonType
,
typename
T
>
void
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
from_json_fn
>
().
call
(
j
,
val
,
priority_tag
<
1
>
{})))
{
return
call
(
j
,
val
,
priority_tag
<
1
>
{});
}
};
}
...
...
single_include/nlohmann/json.hpp
View file @
4b4bbcee
...
...
@@ -1212,8 +1212,8 @@ template <typename BasicJsonType, typename CompatibleArrayType,
auto
from_json
(
const
BasicJsonType
&
j
,
CompatibleArrayType
&
arr
)
->
decltype
(
from_json_array_impl
(
j
,
arr
,
priority_tag
<
3
>
{}),
j
.
template
get
<
typename
CompatibleArrayType
::
value_type
>(),
void
())
j
.
template
get
<
typename
CompatibleArrayType
::
value_type
>(),
void
())
{
if
(
JSON_UNLIKELY
(
not
j
.
is_array
()))
{
...
...
@@ -1344,35 +1344,13 @@ void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyE
struct
from_json_fn
{
private:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
const
BasicJsonType
&
j
,
T
&
val
,
priority_tag
<
1
>
/*unused*/
)
const
auto
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
->
decltype
(
from_json
(
j
,
val
),
void
())
{
return
from_json
(
j
,
val
);
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
const
BasicJsonType
&
/*unused*/
,
T
&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find from_json() method in T's namespace"
);
#ifdef _MSC_VER
// MSVC does not show a stacktrace for the above assert
using
decayed
=
uncvref_t
<
T
>
;
static_assert
(
sizeof
(
typename
decayed
::
force_msvc_stacktrace
)
==
0
,
"forcing MSVC stacktrace to show which T we're talking about."
);
#endif
}
public:
template
<
typename
BasicJsonType
,
typename
T
>
void
operator
()(
const
BasicJsonType
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
from_json_fn
>
().
call
(
j
,
val
,
priority_tag
<
1
>
{})))
{
return
call
(
j
,
val
,
priority_tag
<
1
>
{});
}
};
}
...
...
@@ -11112,8 +11090,10 @@ struct adl_serializer
@param[in,out] val value to write to
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
void
from_json
(
BasicJsonType
&&
j
,
ValueType
&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
static
auto
from_json
(
BasicJsonType
&&
j
,
ValueType
&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
)))
->
decltype
(
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
),
void
()
)
{
::
nlohmann
::
from_json
(
std
::
forward
<
BasicJsonType
>
(
j
),
val
);
}
...
...
test/src/unit-inspection.cpp
View file @
4b4bbcee
...
...
@@ -317,8 +317,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
();
...
...
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