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
f665a923
Commit
f665a923
authored
Nov 07, 2018
by
David Avedissian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement SFINAE friendly iterator_traits and use that instead.
parent
e3c28afb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
20 deletions
+120
-20
include/nlohmann/detail/input/input_adapters.hpp
include/nlohmann/detail/input/input_adapters.hpp
+3
-3
include/nlohmann/detail/iterators/iterator_traits.hpp
include/nlohmann/detail/iterators/iterator_traits.hpp
+47
-0
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+5
-4
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+1
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+64
-12
No files found.
include/nlohmann/detail/input/input_adapters.hpp
View file @
f665a923
...
@@ -331,7 +331,7 @@ class input_adapter
...
@@ -331,7 +331,7 @@ class input_adapter
/// input adapter for iterator range with contiguous storage
/// input adapter for iterator range with contiguous storage
template
<
class
IteratorType
,
template
<
class
IteratorType
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_same
<
typename
std
::
iterator_traits
<
IteratorType
>
::
iterator_category
,
std
::
random_access_iterator_tag
>::
value
,
std
::
is_same
<
typename
iterator_traits
<
IteratorType
>
::
iterator_category
,
std
::
random_access_iterator_tag
>::
value
,
int
>::
type
=
0
>
int
>::
type
=
0
>
input_adapter
(
IteratorType
first
,
IteratorType
last
)
input_adapter
(
IteratorType
first
,
IteratorType
last
)
{
{
...
@@ -350,7 +350,7 @@ class input_adapter
...
@@ -350,7 +350,7 @@ class input_adapter
// assertion to check that each element is 1 byte long
// assertion to check that each element is 1 byte long
static_assert
(
static_assert
(
sizeof
(
typename
std
::
iterator_traits
<
IteratorType
>::
value_type
)
==
1
,
sizeof
(
typename
iterator_traits
<
IteratorType
>::
value_type
)
==
1
,
"each element in the iterator range must have the size of 1 byte"
);
"each element in the iterator range must have the size of 1 byte"
);
const
auto
len
=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
last
));
const
auto
len
=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
last
));
...
@@ -374,7 +374,7 @@ class input_adapter
...
@@ -374,7 +374,7 @@ class input_adapter
/// input adapter for contiguous container
/// input adapter for contiguous container
template
<
class
ContiguousContainer
,
typename
template
<
class
ContiguousContainer
,
typename
std
::
enable_if
<
not
std
::
is_pointer
<
ContiguousContainer
>
::
value
and
std
::
enable_if
<
not
std
::
is_pointer
<
ContiguousContainer
>
::
value
and
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
decltype
(
std
::
begin
(
std
::
declval
<
ContiguousContainer
const
>
()))
>::
iterator_category
>::
value
,
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
iterator_traits
<
decltype
(
std
::
begin
(
std
::
declval
<
ContiguousContainer
const
>
()))
>::
iterator_category
>::
value
,
int
>::
type
=
0
>
int
>::
type
=
0
>
input_adapter
(
const
ContiguousContainer
&
c
)
input_adapter
(
const
ContiguousContainer
&
c
)
:
input_adapter
(
std
::
begin
(
c
),
std
::
end
(
c
))
{}
:
input_adapter
(
std
::
begin
(
c
),
std
::
end
(
c
))
{}
...
...
include/nlohmann/detail/iterators/iterator_traits.hpp
0 → 100644
View file @
f665a923
#pragma once
#include <iterator> // random_access_iterator_tag
#include <nlohmann/detail/meta/void_t.hpp>
namespace
nlohmann
{
namespace
detail
{
template
<
class
It
,
class
=
void
>
struct
_iterator_types
{};
template
<
class
It
>
struct
_iterator_types
<
It
,
void_t
<
typename
It
::
difference_type
,
typename
It
::
value_type
,
typename
It
::
pointer
,
typename
It
::
reference
,
typename
It
::
iterator_category
>>
{
using
difference_type
=
typename
It
::
difference_type
;
using
value_type
=
typename
It
::
value_type
;
using
pointer
=
typename
It
::
pointer
;
using
reference
=
typename
It
::
reference
;
using
iterator_category
=
typename
It
::
iterator_category
;
};
template
<
class
Iter
>
struct
iterator_traits
:
_iterator_types
<
Iter
>
{};
template
<
class
T
>
struct
iterator_traits
<
T
*>
{
typedef
std
::
random_access_iterator_tag
iterator_category
;
typedef
T
value_type
;
typedef
ptrdiff_t
difference_type
;
typedef
T
*
pointer
;
typedef
T
&
reference
;
};
template
<
class
T
>
struct
iterator_traits
<
const
T
*>
{
typedef
std
::
random_access_iterator_tag
iterator_category
;
typedef
T
value_type
;
typedef
ptrdiff_t
difference_type
;
typedef
const
T
*
pointer
;
typedef
const
T
&
reference
;
};
}
}
\ No newline at end of file
include/nlohmann/detail/meta/type_traits.hpp
View file @
f665a923
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include <utility> // declval
#include <utility> // declval
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/macro_scope.hpp>
...
@@ -131,10 +132,10 @@ template <typename T, typename = void>
...
@@ -131,10 +132,10 @@ template <typename T, typename = void>
struct
is_iterator_traits
:
std
::
false_type
{};
struct
is_iterator_traits
:
std
::
false_type
{};
template
<
typename
T
>
template
<
typename
T
>
struct
is_iterator_traits
<
std
::
iterator_traits
<
T
>>
struct
is_iterator_traits
<
iterator_traits
<
T
>>
{
{
private:
private:
using
traits
=
std
::
iterator_traits
<
T
>
;
using
traits
=
iterator_traits
<
T
>
;
public:
public:
static
constexpr
auto
value
=
static
constexpr
auto
value
=
...
@@ -251,7 +252,7 @@ struct is_compatible_array_type_impl <
...
@@ -251,7 +252,7 @@ struct is_compatible_array_type_impl <
// Therefore it is detected as a CompatibleArrayType.
// Therefore it is detected as a CompatibleArrayType.
// The real fix would be to have an Iterable concept.
// The real fix would be to have an Iterable concept.
not
is_iterator_traits
<
not
is_iterator_traits
<
std
::
iterator_traits
<
CompatibleArrayType
>>::
value
>>
iterator_traits
<
CompatibleArrayType
>>::
value
>>
{
{
static
constexpr
bool
value
=
static
constexpr
bool
value
=
std
::
is_constructible
<
BasicJsonType
,
std
::
is_constructible
<
BasicJsonType
,
...
@@ -288,7 +289,7 @@ struct is_constructible_array_type_impl <
...
@@ -288,7 +289,7 @@ struct is_constructible_array_type_impl <
// Therefore it is detected as a ConstructibleArrayType.
// Therefore it is detected as a ConstructibleArrayType.
// The real fix would be to have an Iterable concept.
// The real fix would be to have an Iterable concept.
not
is_iterator_traits
<
not
is_iterator_traits
<
std
::
iterator_traits
<
ConstructibleArrayType
>>::
value
and
iterator_traits
<
ConstructibleArrayType
>>::
value
and
(
std
::
is_same
<
typename
ConstructibleArrayType
::
value_type
,
typename
BasicJsonType
::
array_t
::
value_type
>::
value
or
(
std
::
is_same
<
typename
ConstructibleArrayType
::
value_type
,
typename
BasicJsonType
::
array_t
::
value_type
>::
value
or
has_from_json
<
BasicJsonType
,
has_from_json
<
BasicJsonType
,
...
...
include/nlohmann/json.hpp
View file @
f665a923
...
@@ -41,7 +41,7 @@ SOFTWARE.
...
@@ -41,7 +41,7 @@ SOFTWARE.
#include <functional> // hash, less
#include <functional> // hash, less
#include <initializer_list> // initializer_list
#include <initializer_list> // initializer_list
#include <iosfwd> // istream, ostream
#include <iosfwd> // istream, ostream
#include <iterator> //
iterator_traits,
random_access_iterator_tag
#include <iterator> // random_access_iterator_tag
#include <numeric> // accumulate
#include <numeric> // accumulate
#include <string> // string, stoi, to_string
#include <string> // string, stoi, to_string
#include <utility> // declval, forward, move, pair, swap
#include <utility> // declval, forward, move, pair, swap
...
...
single_include/nlohmann/json.hpp
View file @
f665a923
...
@@ -41,7 +41,7 @@ SOFTWARE.
...
@@ -41,7 +41,7 @@ SOFTWARE.
#include <functional> // hash, less
#include <functional> // hash, less
#include <initializer_list> // initializer_list
#include <initializer_list> // initializer_list
#include <iosfwd> // istream, ostream
#include <iosfwd> // istream, ostream
#include <iterator> //
iterator_traits,
random_access_iterator_tag
#include <iterator> // random_access_iterator_tag
#include <numeric> // accumulate
#include <numeric> // accumulate
#include <string> // string, stoi, to_string
#include <string> // string, stoi, to_string
#include <utility> // declval, forward, move, pair, swap
#include <utility> // declval, forward, move, pair, swap
...
@@ -324,12 +324,10 @@ constexpr T static_const<T>::value;
...
@@ -324,12 +324,10 @@ constexpr T static_const<T>::value;
// #include <nlohmann/json_fwd.hpp>
// #include <nlohmann/json_fwd.hpp>
// #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/iterators/iterator_traits.hpp>
// #include <nlohmann/detail/meta/detected.hpp>
#include <
type_traits>
#include <
iterator> // random_access_iterator_tag
// #include <nlohmann/detail/meta/void_t.hpp>
// #include <nlohmann/detail/meta/void_t.hpp>
...
@@ -347,6 +345,60 @@ template <typename ...Ts> using void_t = typename make_void<Ts...>::type;
...
@@ -347,6 +345,60 @@ template <typename ...Ts> using void_t = typename make_void<Ts...>::type;
}
// namespace nlohmann
}
// namespace nlohmann
namespace
nlohmann
{
namespace
detail
{
template
<
class
It
,
class
=
void
>
struct
_iterator_types
{};
template
<
class
It
>
struct
_iterator_types
<
It
,
void_t
<
typename
It
::
difference_type
,
typename
It
::
value_type
,
typename
It
::
pointer
,
typename
It
::
reference
,
typename
It
::
iterator_category
>>
{
using
difference_type
=
typename
It
::
difference_type
;
using
value_type
=
typename
It
::
value_type
;
using
pointer
=
typename
It
::
pointer
;
using
reference
=
typename
It
::
reference
;
using
iterator_category
=
typename
It
::
iterator_category
;
};
template
<
class
Iter
>
struct
iterator_traits
:
_iterator_types
<
Iter
>
{};
template
<
class
T
>
struct
iterator_traits
<
T
*>
{
typedef
std
::
random_access_iterator_tag
iterator_category
;
typedef
T
value_type
;
typedef
ptrdiff_t
difference_type
;
typedef
T
*
pointer
;
typedef
T
&
reference
;
};
template
<
class
T
>
struct
iterator_traits
<
const
T
*>
{
typedef
std
::
random_access_iterator_tag
iterator_category
;
typedef
T
value_type
;
typedef
ptrdiff_t
difference_type
;
typedef
const
T
*
pointer
;
typedef
const
T
&
reference
;
};
}
}
// #include <nlohmann/detail/meta/cpp_future.hpp>
// #include <nlohmann/detail/meta/detected.hpp>
#include <type_traits>
// #include <nlohmann/detail/meta/void_t.hpp>
// http://en.cppreference.com/w/cpp/experimental/is_detected
// http://en.cppreference.com/w/cpp/experimental/is_detected
namespace
nlohmann
namespace
nlohmann
{
{
...
@@ -522,10 +574,10 @@ template <typename T, typename = void>
...
@@ -522,10 +574,10 @@ template <typename T, typename = void>
struct
is_iterator_traits
:
std
::
false_type
{};
struct
is_iterator_traits
:
std
::
false_type
{};
template
<
typename
T
>
template
<
typename
T
>
struct
is_iterator_traits
<
std
::
iterator_traits
<
T
>>
struct
is_iterator_traits
<
iterator_traits
<
T
>>
{
{
private:
private:
using
traits
=
std
::
iterator_traits
<
T
>
;
using
traits
=
iterator_traits
<
T
>
;
public:
public:
static
constexpr
auto
value
=
static
constexpr
auto
value
=
...
@@ -642,7 +694,7 @@ struct is_compatible_array_type_impl <
...
@@ -642,7 +694,7 @@ struct is_compatible_array_type_impl <
// Therefore it is detected as a CompatibleArrayType.
// Therefore it is detected as a CompatibleArrayType.
// The real fix would be to have an Iterable concept.
// The real fix would be to have an Iterable concept.
not
is_iterator_traits
<
not
is_iterator_traits
<
std
::
iterator_traits
<
CompatibleArrayType
>>::
value
>>
iterator_traits
<
CompatibleArrayType
>>::
value
>>
{
{
static
constexpr
bool
value
=
static
constexpr
bool
value
=
std
::
is_constructible
<
BasicJsonType
,
std
::
is_constructible
<
BasicJsonType
,
...
@@ -679,7 +731,7 @@ struct is_constructible_array_type_impl <
...
@@ -679,7 +731,7 @@ struct is_constructible_array_type_impl <
// Therefore it is detected as a ConstructibleArrayType.
// Therefore it is detected as a ConstructibleArrayType.
// The real fix would be to have an Iterable concept.
// The real fix would be to have an Iterable concept.
not
is_iterator_traits
<
not
is_iterator_traits
<
std
::
iterator_traits
<
ConstructibleArrayType
>>::
value
and
iterator_traits
<
ConstructibleArrayType
>>::
value
and
(
std
::
is_same
<
typename
ConstructibleArrayType
::
value_type
,
typename
BasicJsonType
::
array_t
::
value_type
>::
value
or
(
std
::
is_same
<
typename
ConstructibleArrayType
::
value_type
,
typename
BasicJsonType
::
array_t
::
value_type
>::
value
or
has_from_json
<
BasicJsonType
,
has_from_json
<
BasicJsonType
,
...
@@ -2380,7 +2432,7 @@ class input_adapter
...
@@ -2380,7 +2432,7 @@ class input_adapter
/// input adapter for iterator range with contiguous storage
/// input adapter for iterator range with contiguous storage
template
<
class
IteratorType
,
template
<
class
IteratorType
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_same
<
typename
std
::
iterator_traits
<
IteratorType
>
::
iterator_category
,
std
::
random_access_iterator_tag
>::
value
,
std
::
is_same
<
typename
iterator_traits
<
IteratorType
>
::
iterator_category
,
std
::
random_access_iterator_tag
>::
value
,
int
>::
type
=
0
>
int
>::
type
=
0
>
input_adapter
(
IteratorType
first
,
IteratorType
last
)
input_adapter
(
IteratorType
first
,
IteratorType
last
)
{
{
...
@@ -2399,7 +2451,7 @@ class input_adapter
...
@@ -2399,7 +2451,7 @@ class input_adapter
// assertion to check that each element is 1 byte long
// assertion to check that each element is 1 byte long
static_assert
(
static_assert
(
sizeof
(
typename
std
::
iterator_traits
<
IteratorType
>::
value_type
)
==
1
,
sizeof
(
typename
iterator_traits
<
IteratorType
>::
value_type
)
==
1
,
"each element in the iterator range must have the size of 1 byte"
);
"each element in the iterator range must have the size of 1 byte"
);
const
auto
len
=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
last
));
const
auto
len
=
static_cast
<
size_t
>
(
std
::
distance
(
first
,
last
));
...
@@ -2423,7 +2475,7 @@ class input_adapter
...
@@ -2423,7 +2475,7 @@ class input_adapter
/// input adapter for contiguous container
/// input adapter for contiguous container
template
<
class
ContiguousContainer
,
typename
template
<
class
ContiguousContainer
,
typename
std
::
enable_if
<
not
std
::
is_pointer
<
ContiguousContainer
>
::
value
and
std
::
enable_if
<
not
std
::
is_pointer
<
ContiguousContainer
>
::
value
and
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
decltype
(
std
::
begin
(
std
::
declval
<
ContiguousContainer
const
>
()))
>::
iterator_category
>::
value
,
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
iterator_traits
<
decltype
(
std
::
begin
(
std
::
declval
<
ContiguousContainer
const
>
()))
>::
iterator_category
>::
value
,
int
>::
type
=
0
>
int
>::
type
=
0
>
input_adapter
(
const
ContiguousContainer
&
c
)
input_adapter
(
const
ContiguousContainer
&
c
)
:
input_adapter
(
std
::
begin
(
c
),
std
::
end
(
c
))
{}
:
input_adapter
(
std
::
begin
(
c
),
std
::
end
(
c
))
{}
...
...
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