Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
29f9fe6a
Commit
29f9fe6a
authored
Jan 08, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove one has_to/from_json template parameter
parent
58397957
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
60 deletions
+64
-60
json.hpp
src/json.hpp
+32
-30
json.hpp.re2c
src/json.hpp.re2c
+32
-30
No files found.
src/json.hpp
View file @
29f9fe6a
...
...
@@ -436,7 +436,7 @@ struct is_compatible_integer_type
};
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
template
<
t
emplate
<
typename
,
typename
>
class
JSONSerializer
,
t
ypename
Json
,
typename
T
>
template
<
typename
Json
,
typename
T
>
struct
has_from_json
{
private
:
...
...
@@ -448,39 +448,40 @@ struct has_from_json
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
JSONS
erializer
<
T
,
void
>>
()))
>::
value
;
detect
(
std
::
declval
<
typename
Json
::
template
json_s
erializer
<
T
,
void
>>
()))
>::
value
;
};
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
// this overload is used for non-default-constructible user-defined-types
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
typename
T
>
template
<
typename
Json
,
typename
T
>
struct
has_non_default_from_json
{
private
:
template
<
typename
U
,
typename
=
enable_if_t
<
std
::
is_same
<
T
,
decltype
(
uncvref_t
<
U
>::
from_json
(
std
::
declval
<
Json
>
()))
>::
value
>>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
JSONSerializer
<
T
,
void
>>
()))
>::
value
;
private
:
template
<
typename
U
,
typename
=
enable_if_t
<
std
::
is_same
<
T
,
decltype
(
uncvref_t
<
U
>::
from_json
(
std
::
declval
<
Json
>
()))
>::
value
>>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
Json
::
template
json_serializer
<
T
,
void
>>
()))
>::
value
;
};
// This trait checks if JSONSerializer<T>::to_json exists
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
typename
T
>
// This trait checks if Json::json_serializer<T>::to_json exists
template
<
typename
Json
,
typename
T
>
struct
has_to_json
{
private
:
template
<
typename
U
,
typename
=
decltype
(
uncvref_t
<
U
>::
to_json
(
std
::
declval
<
Json
&>
(),
std
::
declval
<
T
>
()))
>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
JSONS
erializer
<
T
,
void
>>
()))
>::
value
;
private
:
template
<
typename
U
,
typename
=
decltype
(
uncvref_t
<
U
>::
to_json
(
std
::
declval
<
Json
&>
(),
std
::
declval
<
T
>
()))
>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
Json
::
template
json_s
erializer
<
T
,
void
>>
()))
>::
value
;
};
// overloads for basic_json template parameters
...
...
@@ -900,6 +901,8 @@ class basic_json
template
<
typename
U
>
class
iter_impl
;
template
<
typename
Base
>
class
json_reverse_iterator
;
class
json_pointer
;
template
<
typename
T
,
typename
SFINAE
>
using
json_serializer
=
JSONSerializer
<
T
,
SFINAE
>
;
/////////////////////
// container types //
...
...
@@ -1790,7 +1793,7 @@ class basic_json
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
<
JSONSerializer
,
basic_json
,
U
>::
value
,
detail
::
has_to_json
<
basic_json
,
U
>::
value
,
int
>
=
0
>
basic_json
(
T
&&
val
)
{
...
...
@@ -2957,10 +2960,9 @@ class basic_json
template
<
typename
T
,
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>>::
value
and
detail
::
has_from_json
<
JSONSerializer
,
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
<
JSONSerializer
,
basic_json_t
,
uncvref_t
<
T
>>::
value
,
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ?
...
...
@@ -2983,8 +2985,8 @@ class basic_json
template
<
typename
T
,
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>>::
value
and
detail
::
has_non_default_from_json
<
JSONSerializer
,
basic_json_t
,
uncvref_t
<
T
>>::
value
,
detail
::
has_non_default_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
uncvref_t
<
T
>
get
()
const
{
...
...
src/json.hpp.re2c
View file @
29f9fe6a
...
...
@@ -436,7 +436,7 @@ struct is_compatible_integer_type
};
// This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
template <t
emplate <typename, typename> class JSONSerializer, t
ypename Json, typename T>
template <typename Json, typename T>
struct has_from_json
{
private:
...
...
@@ -448,39 +448,40 @@ struct has_from_json
public:
static constexpr bool value = std::is_integral<decltype(
detect(std::declval<
JSONS
erializer<T, void>>()))>::value;
detect(std::declval<
typename Json::template json_s
erializer<T, void>>()))>::value;
};
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
// this overload is used for non-default-constructible user-defined-types
template <template <typename, typename> class JSONSerializer, typename Json,
typename T>
template <typename Json, typename T>
struct has_non_default_from_json
{
private:
template <typename U, typename = enable_if_t<std::is_same<T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
static int detect(U&&);
static void detect(...);
public:
static constexpr bool value = std::is_integral<decltype(
detect(std::declval<JSONSerializer<T, void>>()))>::value;
private:
template <
typename U,
typename = enable_if_t<std::is_same<
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value>>
static int detect(U &&);
static void detect(...);
public:
static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
};
// This trait checks if JSONSerializer<T>::to_json exists
template <template <typename, typename> class JSONSerializer, typename Json,
typename T>
// This trait checks if Json::json_serializer<T>::to_json exists
template <typename Json, typename T>
struct has_to_json
{
private:
template <typename U, typename = decltype(uncvref_t<U>::to_json(
std::declval<Json
&>(), std::declval<T>()))>
static int detect(U
&&);
static void detect(...);
public:
static constexpr bool value = std::is_integral<decltype
(
detect(std::declval<JSONS
erializer<T, void>>()))>::value;
private:
template <typename U, typename = decltype(uncvref_t<U>::to_json(
std::declval<Json
&>(), std::declval<T>()))>
static int detect(U
&&);
static void detect(...);
public:
static constexpr bool value = std::is_integral<decltype(detect
(
std::declval<typename Json::template json_s
erializer<T, void>>()))>::value;
};
// overloads for basic_json template parameters
...
...
@@ -900,6 +901,8 @@ class basic_json
template<typename U> class iter_impl;
template<typename Base> class json_reverse_iterator;
class json_pointer;
template <typename T, typename SFINAE>
using json_serializer = JSONSerializer<T, SFINAE>;
/////////////////////
// container types //
...
...
@@ -1790,7 +1793,7 @@ class basic_json
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<
JSONSerializer,
basic_json, U>::value,
detail::has_to_json<basic_json, U>::value,
int> = 0>
basic_json(T &&val)
{
...
...
@@ -2957,10 +2960,9 @@ class basic_json
template <
typename T,
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_from_json<JSONSerializer, 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<
JSONSerializer,
basic_json_t, uncvref_t<T>>::value,
basic_json_t, uncvref_t<T>>::value,
int> = 0>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ?
...
...
@@ -2983,8 +2985,8 @@ class basic_json
template <
typename T,
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_non_default_from_json<
JSONSerializer, basic_json_t,
uncvref_t<T>>::value,
detail::has_non_default_from_json<
basic_json_t,
uncvref_t<T>>::value,
int> = 0>
uncvref_t<T> get() const
{
...
...
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