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
1f25ec5d
Commit
1f25ec5d
authored
Jan 09, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some constexpr + noexcept
parent
29f9fe6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
32 deletions
+40
-32
src/json.hpp
src/json.hpp
+20
-16
src/json.hpp.re2c
src/json.hpp.re2c
+20
-16
No files found.
src/json.hpp
View file @
1f25ec5d
...
...
@@ -1789,15 +1789,16 @@ class basic_json
// - JSONSerializer::to_json exists for type T
// - T is not a istream, nor convertible to basic_json (float, vectors, etc)
template
<
typename
T
,
typename
U
=
uncvref_t
<
T
>,
enable_if_t
<
not
std
::
is_base_of
<
std
::
istream
,
U
>::
value
and
not
std
::
is_same
<
U
,
basic_json_t
>::
value
and
not
detail
::
is_basic_json_nested_type
<
basic_json_t
,
U
>::
value
and
detail
::
has_to_json
<
basic_json
,
U
>::
value
,
int
>
=
0
>
basic_json
(
T
&&
val
)
enable_if_t
<
not
std
::
is_base_of
<
std
::
istream
,
U
>::
value
and
not
std
::
is_same
<
U
,
basic_json_t
>::
value
and
not
detail
::
is_basic_json_nested_type
<
basic_json_t
,
U
>::
value
and
detail
::
has_to_json
<
basic_json
,
U
>::
value
,
int
>
=
0
>
basic_json
(
T
&&
val
)
noexcept
(
noexcept
(
JSONSerializer
<
U
>::
to_json
(
std
::
declval
<
basic_json_t
&>
(),
std
::
forward
<
T
>
(
val
))))
{
JSONSerializer
<
uncvref_t
<
T
>
>::
to_json
(
*
this
,
std
::
forward
<
T
>
(
val
));
JSONSerializer
<
U
>::
to_json
(
*
this
,
std
::
forward
<
T
>
(
val
));
}
/*!
...
...
@@ -2959,14 +2960,18 @@ class basic_json
// the latter is preferred if both are present (since it does not require a default construction of T)
template
<
typename
T
,
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>
>::
value
and
detail
::
has_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
and
not
detail
::
has_non_default_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>
>::
value
and
detail
::
has_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
and
not
detail
::
has_non_default_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// i know there is a special behaviour for boolean_t* and such
// static assert ?
auto
get
()
const
->
uncvref_t
<
T
>
auto
get
()
const
noexcept
(
noexcept
(
JSONSerializer
<
uncvref_t
<
T
>>::
from_json
(
std
::
declval
<
basic_json_t
const
&>
(),
std
::
declval
<
uncvref_t
<
T
>
&>
())))
->
uncvref_t
<
T
>
{
using
type
=
uncvref_t
<
T
>
;
static_assert
(
std
::
is_default_constructible
<
type
>::
value
&&
...
...
@@ -2981,14 +2986,13 @@ class basic_json
// This overload is chosen when:
// - T is not basic_json_t
// - and JSONSerializer<T>::from_json(basic_json const&) does not exist
// TODO add constexpr, noexcept(...)
template
<
typename
T
,
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>
>::
value
and
detail
::
has_non_default_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
uncvref_t
<
T
>
get
()
const
constexpr
uncvref_t
<
T
>
get
()
const
noexcept
(
noexcept
(
JSONSerializer
<
T
>::
from_json
(
std
::
declval
<
basic_json_t
const
&>
())))
{
return
JSONSerializer
<
T
>::
from_json
(
*
this
);
}
...
...
src/json.hpp.re2c
View file @
1f25ec5d
...
...
@@ -1789,15 +1789,16 @@ class basic_json
// - JSONSerializer::to_json exists for type T
// - T is not a istream, nor convertible to basic_json (float, vectors, etc)
template <typename T, typename U = uncvref_t<T>,
enable_if_t<
not std::is_base_of<std::istream, U>::value and
not std::is_same<U, basic_json_t>::value and
not detail::is_basic_json_nested_type<basic_json_t,U>::value and
detail::has_to_json<basic_json, U>::value,
int> = 0>
basic_json(T &&val)
enable_if_t<not std::is_base_of<std::istream, U>::value and
not std::is_same<U, basic_json_t>::value and
not detail::is_basic_json_nested_type<
basic_json_t, U>::value and
detail::has_to_json<basic_json, U>::value,
int> = 0>
basic_json(T &&val) noexcept(noexcept(JSONSerializer<U>::to_json(
std::declval<basic_json_t &>(), std::forward<T>(val))))
{
JSONSerializer<
uncvref_t<T>
>::to_json(*this, std::forward<T>(val));
JSONSerializer<
U
>::to_json(*this, std::forward<T>(val));
}
/*!
...
...
@@ -2959,14 +2960,18 @@ class basic_json
// the latter is preferred if both are present (since it does not require a default construction of T)
template <
typename T,
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_from_json<basic_json_t, uncvref_t<T>>::value and
not detail::has_non_default_from_json<
basic_json_t, uncvref_t<T>>::value,
int> = 0>
enable_if_t<
not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_from_json<basic_json_t, uncvref_t<T>>::value and
not detail::has_non_default_from_json<basic_json_t,
uncvref_t<T>>::value,
int> = 0>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// i know there is a special behaviour for boolean_t* and such
// static assert ?
auto get() const -> uncvref_t<T>
auto get() const noexcept(noexcept(JSONSerializer<uncvref_t<T>>::from_json(
std::declval<basic_json_t const &>(), std::declval<uncvref_t<T> &>())))
-> uncvref_t<T>
{
using type = uncvref_t<T>;
static_assert(std::is_default_constructible<type>::value &&
...
...
@@ -2981,14 +2986,13 @@ class basic_json
// This overload is chosen when:
// - T is not basic_json_t
// - and JSONSerializer<T>::from_json(basic_json const&) does not exist
// TODO add constexpr, noexcept(...)
template <
typename T,
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_non_default_from_json<basic_json_t,
uncvref_t<T>>::value,
int> = 0>
uncvref_t<T> get() const
constexpr uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<basic_json_t const&>())))
{
return JSONSerializer<T>::from_json(*this);
}
...
...
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