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
f7971f04
Unverified
Commit
f7971f04
authored
7 years ago
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make to_json SFINAE-correct
parent
f7c8a214
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
58 deletions
+22
-58
include/nlohmann/adl_serializer.hpp
include/nlohmann/adl_serializer.hpp
+4
-2
include/nlohmann/detail/conversions/to_json.hpp
include/nlohmann/detail/conversions/to_json.hpp
+7
-27
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+11
-29
No files found.
include/nlohmann/adl_serializer.hpp
View file @
f7971f04
...
...
@@ -35,9 +35,11 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
void
to_json
(
BasicJsonType
&
j
,
ValueType
&&
val
)
noexcept
(
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
auto
to_json
(
BasicJsonType
&
j
,
ValueType
&&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
))))
->
decltype
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
)),
void
())
{
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
));
}
...
...
This diff is collapsed.
Click to expand it.
include/nlohmann/detail/conversions/to_json.hpp
View file @
f7971f04
...
...
@@ -286,9 +286,12 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
obj
));
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
T
(
&
)[
N
]>
::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
const
T
(
&
)[
N
]
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
T
(
&
arr
)[
N
])
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
...
...
@@ -321,35 +324,12 @@ void to_json(BasicJsonType& j, const std::tuple<Args...>& t)
struct
to_json_fn
{
private:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
BasicJsonType
&
j
,
T
&&
val
,
priority_tag
<
1
>
/*unused*/
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
auto
operator
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
)),
void
())
{
return
to_json
(
j
,
std
::
forward
<
T
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
BasicJsonType
&
/*unused*/
,
T
&&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find to_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
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
{
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
}
};
}
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
f7971f04
...
...
@@ -1807,9 +1807,12 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
obj
));
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
T
(
&
)[
N
]>
::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
,
enable_if_t
<
not
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
const
T
(
&
)[
N
]
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
const
T
(
&
arr
)[
N
])
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
...
...
@@ -1842,35 +1845,12 @@ void to_json(BasicJsonType& j, const std::tuple<Args...>& t)
struct
to_json_fn
{
private:
template
<
typename
BasicJsonType
,
typename
T
>
auto
call
(
BasicJsonType
&
j
,
T
&&
val
,
priority_tag
<
1
>
/*unused*/
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
auto
operator
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
j
,
std
::
forward
<
T
>
(
val
)),
void
())
{
return
to_json
(
j
,
std
::
forward
<
T
>
(
val
));
}
template
<
typename
BasicJsonType
,
typename
T
>
void
call
(
BasicJsonType
&
/*unused*/
,
T
&&
/*unused*/
,
priority_tag
<
0
>
/*unused*/
)
const
noexcept
{
static_assert
(
sizeof
(
BasicJsonType
)
==
0
,
"could not find to_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
()(
BasicJsonType
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
{
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
}
};
}
...
...
@@ -11147,9 +11127,11 @@ struct adl_serializer
@param[in,out] j JSON value to write to
@param[in] val value to read from
*/
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
void
to_json
(
BasicJsonType
&
j
,
ValueType
&&
val
)
noexcept
(
template
<
typename
BasicJsonType
,
typename
ValueType
>
static
auto
to_json
(
BasicJsonType
&
j
,
ValueType
&&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
))))
->
decltype
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
)),
void
())
{
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
ValueType
>
(
val
));
}
...
...
This diff is collapsed.
Click to expand it.
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