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
b59c3367
Unverified
Commit
b59c3367
authored
Sep 05, 2018
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use detected instead of has_* traits
parent
1ea8cd12
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
182 deletions
+161
-182
include/nlohmann/detail/macro_scope.hpp
include/nlohmann/detail/macro_scope.hpp
+0
-19
include/nlohmann/detail/macro_unscope.hpp
include/nlohmann/detail/macro_unscope.hpp
+0
-1
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+45
-36
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+116
-126
No files found.
include/nlohmann/detail/macro_scope.hpp
View file @
b59c3367
...
...
@@ -102,22 +102,3 @@
basic_json<ObjectType, ArrayType, StringType, BooleanType, \
NumberIntegerType, NumberUnsignedType, NumberFloatType, \
AllocatorType, JSONSerializer>
/*!
@brief Helper to determine whether there's a key_type for T.
This helper is used to tell associative containers apart from other containers
such as sequence containers. For instance, `std::map` passes the test as it
contains a `mapped_type`, whereas `std::vector` fails the test.
@sa http://stackoverflow.com/a/7728728/266378
@since version 1.0.0, overworked in version 2.0.6
*/
#define NLOHMANN_JSON_HAS_HELPER(type) \
template<typename T> struct has_##type { \
template<typename U, typename = typename U::type> \
static int detect(U &&); \
static void detect(...); \
static constexpr bool value = \
std::is_integral<decltype(detect(std::declval<T>()))>::value; \
}
include/nlohmann/detail/macro_unscope.hpp
View file @
b59c3367
...
...
@@ -20,4 +20,3 @@
#undef JSON_HAS_CPP_17
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
#undef NLOHMANN_BASIC_JSON_TPL
#undef NLOHMANN_JSON_HAS_HELPER
include/nlohmann/detail/meta/type_traits.hpp
View file @
b59c3367
...
...
@@ -7,6 +7,7 @@
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/macro_scope.hpp>
namespace
nlohmann
...
...
@@ -30,9 +31,31 @@ template<typename> struct is_basic_json : std::false_type {};
NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct
is_basic_json
<
NLOHMANN_BASIC_JSON_TPL
>
:
std
::
true_type
{};
////////////////////////
// has_/is_ functions //
////////////////////////
//////////////////////////
// aliases for detected //
//////////////////////////
template
<
typename
T
>
using
mapped_type_t
=
typename
T
::
mapped_type
;
template
<
typename
T
>
using
key_type_t
=
typename
T
::
key_type
;
template
<
typename
T
>
using
value_type_t
=
typename
T
::
value_type
;
template
<
typename
T
>
using
iterator_t
=
typename
T
::
iterator
;
template
<
typename
T
,
typename
...
Args
>
using
to_json_function
=
decltype
(
T
::
to_json
(
std
::
declval
<
Args
>
()...));
template
<
typename
T
,
typename
...
Args
>
using
from_json_function
=
decltype
(
T
::
from_json
(
std
::
declval
<
Args
>
()...));
///////////////////
// is_ functions //
///////////////////
// source: https://stackoverflow.com/a/37193089/4116453
...
...
@@ -42,11 +65,6 @@ struct is_complete_type : std::false_type {};
template
<
typename
T
>
struct
is_complete_type
<
T
,
decltype
(
void
(
sizeof
(
T
)))
>
:
std
::
true_type
{};
NLOHMANN_JSON_HAS_HELPER
(
mapped_type
);
NLOHMANN_JSON_HAS_HELPER
(
key_type
);
NLOHMANN_JSON_HAS_HELPER
(
value_type
);
NLOHMANN_JSON_HAS_HELPER
(
iterator
);
template
<
bool
B
,
class
RealType
,
class
CompatibleObjectType
>
struct
is_compatible_object_type_impl
:
std
::
false_type
{};
...
...
@@ -74,8 +92,8 @@ struct is_compatible_object_type
{
static
auto
constexpr
value
=
is_compatible_object_type_impl
<
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleObjectType
>>
,
has_mapped_type
<
CompatibleObjectType
>
,
has_key_type
<
CompatibleObjectType
>>::
value
,
is_detected
<
mapped_type_t
,
CompatibleObjectType
>
,
is_detected
<
key_type_t
,
CompatibleObjectType
>>::
value
,
typename
BasicJsonType
::
object_t
,
CompatibleObjectType
>::
value
;
};
...
...
@@ -84,7 +102,7 @@ struct is_compatible_string_type
{
static
auto
constexpr
value
=
is_compatible_string_type_impl
<
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleStringType
>>
,
has_value_type
<
CompatibleStringType
>>::
value
,
is_detected
<
value_type_t
,
CompatibleStringType
>>::
value
,
typename
BasicJsonType
::
string_t
,
CompatibleStringType
>::
value
;
};
...
...
@@ -107,8 +125,8 @@ struct is_compatible_array_type
negation
<
std
::
is_constructible
<
typename
BasicJsonType
::
string_t
,
CompatibleArrayType
>>
,
negation
<
is_basic_json_nested_type
<
BasicJsonType
,
CompatibleArrayType
>>
,
has_value_type
<
CompatibleArrayType
>
,
has_iterator
<
CompatibleArrayType
>>::
value
;
is_detected
<
value_type_t
,
CompatibleArrayType
>
,
is_detected
<
iterator_t
,
CompatibleArrayType
>>::
value
;
};
template
<
bool
,
typename
,
typename
>
...
...
@@ -141,14 +159,11 @@ struct is_compatible_integer_type
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_from_json
{
// also check the return type of from_json
template
<
typename
U
,
typename
=
enable_if_t
<
std
::
is_same
<
void
,
decltype
(
uncvref_t
<
U
>
::
from_json
(
std
::
declval
<
BasicJsonType
>
(),
std
::
declval
<
T
&>
()))
>::
value
>>
static
int
detect
(
U
&&
);
static
void
detect
(...);
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
>
()))
>::
value
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>;
static
constexpr
bool
value
=
is_detected_exact
<
void
,
from_json_function
,
serializer
,
const
BasicJsonType
&
,
T
&>::
value
;
};
// This trait checks if JSONSerializer<T>::from_json(json const&) exists
...
...
@@ -156,28 +171,22 @@ struct has_from_json
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_non_default_from_json
{
template
<
typename
U
,
typename
=
enable_if_t
<
std
::
is_same
<
T
,
decltype
(
uncvref_t
<
U
>
::
from_json
(
std
::
declval
<
BasicJsonType
>
()))
>::
value
>>
static
int
detect
(
U
&&
);
static
void
detect
(...);
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
>
()))
>::
value
;
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>;
static
constexpr
bool
value
=
is_detected_exact
<
T
,
from_json_function
,
serializer
,
const
BasicJsonType
&>::
value
;
};
// This trait checks if BasicJsonType::json_serializer<T>::to_json exists
template
<
typename
BasicJsonType
,
typename
T
>
struct
has_to_json
{
template
<
typename
U
,
typename
=
decltype
(
uncvref_t
<
U
>
::
to_json
(
std
::
declval
<
BasicJsonType
&>
(),
std
::
declval
<
T
>
()))
>
static
int
detect
(
U
&&
);
static
void
detect
(...);
using
serializer
=
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>;
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
BasicJsonType
::
template
json_serializer
<
T
,
void
>
>
()))
>::
value
;
static
constexpr
bool
value
=
is_detected_exact
<
void
,
to_json_function
,
serializer
,
BasicJsonType
&
,
T
>::
value
;
};
template
<
typename
BasicJsonType
,
typename
CompatibleCompleteType
>
...
...
single_include/nlohmann/json.hpp
View file @
b59c3367
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