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
1eafac72
Commit
1eafac72
authored
Dec 04, 2016
by
Théo DELRIEU
Committed by
Théo DELRIEU
Jan 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove explicit keyword on udt-constructor
parent
c0c72b5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
47 deletions
+49
-47
json.hpp
src/json.hpp
+40
-38
unit-udt.cpp
test/src/unit-udt.cpp
+9
-9
No files found.
src/json.hpp
View file @
1eafac72
...
@@ -257,36 +257,33 @@ struct is_compatible_integer_type_impl<true, RealIntegerType, CompatibleNumberIn
...
@@ -257,36 +257,33 @@ struct is_compatible_integer_type_impl<true, RealIntegerType, CompatibleNumberIn
RealLimits
::
is_signed
==
CompatibleLimits
::
is_signed
;
RealLimits
::
is_signed
==
CompatibleLimits
::
is_signed
;
};
};
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
struct
is_compatible_integer_type
{
static
constexpr
auto
value
=
is_compatible_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberIntegerType
>::
value
,
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
;
};
// quickfix, just trying to make things compile before refactoring
// quickfix, just trying to make things compile before refactoring
template
<
bool
B
,
typename
RealIntegerType
,
typename
CompatibleEnumType
>
template
<
bool
B
,
typename
RealIntegerType
,
typename
CompatibleEnumType
>
struct
is_compatible_enum_type_impl
:
std
::
false_type
{};
struct
is_compatible_enum_type_impl
:
std
::
false_type
{};
template
<
typename
RealIntegerType
,
typename
CompatibleEnumType
>
template
<
typename
RealIntegerType
,
typename
CompatibleEnumType
>
struct
is_compatible_enum_type_impl
<
true
,
RealIntegerType
,
CompatibleEnumType
>
struct
is_compatible_enum_type_impl
<
true
,
RealIntegerType
,
CompatibleEnumType
>
{
{
using
RealLimits
=
std
::
numeric_limits
<
RealIntegerType
>
;
using
Underlying
=
typename
std
::
underlying_type
<
CompatibleEnumType
>::
type
;
using
CompatibleLimits
=
std
::
numeric_limits
<
typename
std
::
underlying_type
<
CompatibleEnumType
>::
type
>
;
static
constexpr
auto
value
=
static
constexpr
auto
value
=
CompatibleLimits
::
is_integer
and
is_compatible_integer_type
<
RealIntegerType
,
Underlying
>::
value
;
RealLimits
::
is_signed
==
CompatibleLimits
::
is_signed
;
};
};
template
<
typename
RealIntegerType
,
typename
CompatibleEnumType
>
template
<
typename
RealIntegerType
,
typename
CompatibleEnumType
>
struct
is_compatible_enum_type
struct
is_compatible_enum_type
{
{
static
constexpr
auto
value
=
is_compatible_enum_type_impl
<
static
constexpr
auto
value
=
// quickfix for all enums
is_compatible_enum_type_impl
<
std
::
is_enum
<
CompatibleEnumType
>::
value
,
std
::
is_enum
<
CompatibleEnumType
>::
value
,
RealIntegerType
,
RealIntegerType
,
CompatibleEnumType
>::
value
;
CompatibleEnumType
>::
value
;
};
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
struct
is_compatible_integer_type
{
static
constexpr
auto
value
=
is_compatible_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberIntegerType
>::
value
,
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
;
};
};
template
<
typename
RealFloat
,
typename
CompatibleFloat
>
template
<
typename
RealFloat
,
typename
CompatibleFloat
>
...
@@ -306,6 +303,7 @@ struct is_compatible_basic_json_type
...
@@ -306,6 +303,7 @@ struct is_compatible_basic_json_type
std
::
is_same
<
typename
BasicJson
::
boolean_t
,
T
>::
value
or
std
::
is_same
<
typename
BasicJson
::
boolean_t
,
T
>::
value
or
is_compatible_array_type
<
BasicJson
,
T
>::
value
or
is_compatible_array_type
<
BasicJson
,
T
>::
value
or
is_compatible_enum_type
<
T
,
typename
BasicJson
::
number_integer_t
>::
value
or
is_compatible_enum_type
<
T
,
typename
BasicJson
::
number_integer_t
>::
value
or
is_compatible_enum_type
<
T
,
typename
BasicJson
::
number_unsigned_t
>::
value
or
is_compatible_object_type
<
typename
BasicJson
::
object_t
,
T
>::
value
or
is_compatible_object_type
<
typename
BasicJson
::
object_t
,
T
>::
value
or
is_compatible_float_type
<
typename
BasicJson
::
number_float_t
,
T
>::
value
or
is_compatible_float_type
<
typename
BasicJson
::
number_float_t
,
T
>::
value
or
is_compatible_integer_type
<
typename
BasicJson
::
number_integer_t
,
is_compatible_integer_type
<
typename
BasicJson
::
number_integer_t
,
...
@@ -1627,8 +1625,8 @@ class basic_json
...
@@ -1627,8 +1625,8 @@ class basic_json
uncvref_t
<
T
>
,
basic_json_t
>::
value
and
uncvref_t
<
T
>
,
basic_json_t
>::
value
and
not
detail
::
is_basic_json_nested_class
<
uncvref_t
<
T
>
,
basic_json_t
,
primitive_iterator_t
>::
value
and
not
detail
::
is_basic_json_nested_class
<
uncvref_t
<
T
>
,
basic_json_t
,
primitive_iterator_t
>::
value
and
not
std
::
is_same
<
uncvref_t
<
T
>
,
typename
basic_json_t
::
array_t
::
iterator
>::
value
and
not
std
::
is_same
<
uncvref_t
<
T
>
,
typename
basic_json_t
::
array_t
::
iterator
>::
value
and
// quickfix
not
detail
::
is_compatible_enum_type
<
number_integer_t
,
uncvref_t
<
T
>>::
value
and
not
std
::
is_enum
<
uncvref_t
<
T
>>::
value
and
not
detail
::
is_compatible_enum_type
<
number_unsigned_t
,
uncvref_t
<
T
>>::
value
and
not
std
::
is_same
<
uncvref_t
<
T
>
,
typename
basic_json_t
::
object_t
::
iterator
>::
value
and
not
std
::
is_same
<
uncvref_t
<
T
>
,
typename
basic_json_t
::
object_t
::
iterator
>::
value
and
detail
::
has_to_json
<
JSONSerializer
,
basic_json
,
detail
::
has_to_json
<
JSONSerializer
,
basic_json
,
uncvref_t
<
T
>>::
value
,
uncvref_t
<
T
>>::
value
,
...
@@ -1831,17 +1829,17 @@ not std::is_enum<uncvref_t<T>>::value and
...
@@ -1831,17 +1829,17 @@ not std::is_enum<uncvref_t<T>>::value and
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
template
<
typename
CompatibleNumberIntegerType
,
typename
CompatibleNumberIntegerType
,
enable_if_t
<
enable_if_t
<
detail
::
is_compatible_integer_type
<
detail
::
is_compatible_integer_type
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
or
number_integer_t
,
CompatibleNumberIntegerType
>::
value
or
detail
::
is_compatible_enum_type
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
detail
::
is_compatible_enum_type
<
int
>
=
0
>
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
basic_json
(
const
CompatibleNumberIntegerType
val
)
noexcept
basic_json
(
const
CompatibleNumberIntegerType
val
)
noexcept
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
val
))
m_value
(
static_cast
<
number_integer_t
>
(
val
))
{
{
assert_invariant
();
assert_invariant
();
}
}
/*!
/*!
...
@@ -1892,14 +1890,16 @@ detail::is_compatible_enum_type<number_integer_t, CompatibleNumberIntegerType>::
...
@@ -1892,14 +1890,16 @@ detail::is_compatible_enum_type<number_integer_t, CompatibleNumberIntegerType>::
*/
*/
template
<
template
<
typename
CompatibleNumberUnsignedType
,
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
detail
::
is_compatible_integer_type
<
enable_if_t
<
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
detail
::
is_compatible_integer_type
<
int
>
=
0
>
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
or
detail
::
is_compatible_enum_type
<
number_integer_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
basic_json
(
const
CompatibleNumberUnsignedType
val
)
noexcept
basic_json
(
const
CompatibleNumberUnsignedType
val
)
noexcept
:
m_type
(
value_t
::
number_unsigned
),
:
m_type
(
value_t
::
number_unsigned
),
m_value
(
static_cast
<
number_unsigned_t
>
(
val
))
m_value
(
static_cast
<
number_unsigned_t
>
(
val
))
{
{
assert_invariant
();
assert_invariant
();
}
}
/*!
/*!
...
@@ -8603,12 +8603,14 @@ detail::is_compatible_enum_type<number_integer_t, CompatibleNumberIntegerType>::
...
@@ -8603,12 +8603,14 @@ detail::is_compatible_enum_type<number_integer_t, CompatibleNumberIntegerType>::
return
lhs
.
m_it
>=
rhs
.
m_it
;
return
lhs
.
m_it
>=
rhs
.
m_it
;
}
}
friend
constexpr
bool
operator
+
(
primitive_iterator_t
lhs
,
primitive_iterator_t
rhs
)
noexcept
primitive_iterator_t
operator
+
(
difference_type
i
)
{
{
return
lhs
.
m_it
+
rhs
.
m_it
;
auto
result
=
*
this
;
result
+=
i
;
return
result
;
}
}
friend
constexpr
bool
operator
-
(
primitive_iterator_t
lhs
,
primitive_iterator_t
rhs
)
noexcept
friend
constexpr
difference_type
operator
-
(
primitive_iterator_t
lhs
,
primitive_iterator_t
rhs
)
noexcept
{
{
return
lhs
.
m_it
-
rhs
.
m_it
;
return
lhs
.
m_it
-
rhs
.
m_it
;
}
}
...
...
test/src/unit-udt.cpp
View file @
1eafac72
...
@@ -85,7 +85,7 @@ namespace udt
...
@@ -85,7 +85,7 @@ namespace udt
void
to_json
(
nlohmann
::
json
&
j
,
person
const
&
p
)
void
to_json
(
nlohmann
::
json
&
j
,
person
const
&
p
)
{
{
using
nlohmann
::
json
;
using
nlohmann
::
json
;
j
=
json
{{
"age"
,
json
{
p
.
m_age
}},
{
"name"
,
json
{
p
.
m_name
}
}};
j
=
json
{{
"age"
,
p
.
m_age
},
{
"name"
,
p
.
m_name
}};
}
}
void
to_json
(
nlohmann
::
json
&
j
,
address
const
&
a
)
void
to_json
(
nlohmann
::
json
&
j
,
address
const
&
a
)
...
@@ -96,13 +96,13 @@ namespace udt
...
@@ -96,13 +96,13 @@ namespace udt
void
to_json
(
nlohmann
::
json
&
j
,
contact
const
&
c
)
void
to_json
(
nlohmann
::
json
&
j
,
contact
const
&
c
)
{
{
using
nlohmann
::
json
;
using
nlohmann
::
json
;
j
=
json
{{
"person"
,
json
{
c
.
m_person
}},
{
"address"
,
json
{
c
.
m_address
}
}};
j
=
json
{{
"person"
,
c
.
m_person
},
{
"address"
,
c
.
m_address
}};
}
}
void
to_json
(
nlohmann
::
json
&
j
,
contact_book
const
&
cb
)
void
to_json
(
nlohmann
::
json
&
j
,
contact_book
const
&
cb
)
{
{
using
nlohmann
::
json
;
using
nlohmann
::
json
;
j
=
json
{{
"name"
,
json
{
cb
.
m_book_name
}
},
{
"contacts"
,
cb
.
m_contacts
}};
j
=
json
{{
"name"
,
cb
.
m_book_name
},
{
"contacts"
,
cb
.
m_contacts
}};
}
}
// operators
// operators
...
@@ -190,15 +190,15 @@ TEST_CASE("basic usage", "[udt]")
...
@@ -190,15 +190,15 @@ TEST_CASE("basic usage", "[udt]")
SECTION
(
"conversion to json via free-functions"
)
SECTION
(
"conversion to json via free-functions"
)
{
{
CHECK
(
json
{
a
}
==
json
(
23
));
CHECK
(
json
(
a
)
==
json
(
23
));
CHECK
(
json
{
n
}
==
json
(
"theo"
));
CHECK
(
json
(
n
)
==
json
(
"theo"
));
CHECK
(
json
{
sfinae_addict
}
==
R"({"name":"theo", "age":23})"
_json
);
CHECK
(
json
(
sfinae_addict
)
==
R"({"name":"theo", "age":23})"
_json
);
CHECK
(
json
(
"Paris"
)
==
json
{
addr
}
);
CHECK
(
json
(
"Paris"
)
==
json
(
addr
)
);
CHECK
(
json
{
cpp_programmer
}
==
CHECK
(
json
(
cpp_programmer
)
==
R"({"person" : {"age":23, "name":"theo"}, "address":"Paris"})"
_json
);
R"({"person" : {"age":23, "name":"theo"}, "address":"Paris"})"
_json
);
CHECK
(
CHECK
(
json
{
book
}
==
json
(
book
)
==
R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo"}, "address":"Paris"}, {"person" : {"age":23, "name":"theo"}, "address":"Paris"}]})"
_json
);
R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo"}, "address":"Paris"}, {"person" : {"age":23, "name":"theo"}, "address":"Paris"}]})"
_json
);
}
}
...
...
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