jsoncons 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/jsoncons/extconf.rb +43 -0
- data/ext/jsoncons/jsoncons.cpp +161 -0
- data/ext/jsoncons/jsoncons.h +10 -0
- data/jsoncons.gemspec +44 -0
- data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
- data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
- data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
- data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
- data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
- data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
- data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
- data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
- data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
- data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
- data/lib/jsoncons/version.rb +5 -0
- data/lib/jsoncons.rb +33 -0
- data/test/jsoncons_test.rb +108 -0
- data/test/test_helper.rb +7 -0
- metadata +268 -0
@@ -0,0 +1,884 @@
|
|
1
|
+
// Copyright 2013 Daniel Parker
|
2
|
+
// Distributed under the Boost license, Version 1.0.
|
3
|
+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
4
|
+
|
5
|
+
// See https://github.com/danielaparker/jsoncons for latest version
|
6
|
+
|
7
|
+
#ifndef JSONCONS_TRAITS_EXTENSION_HPP
|
8
|
+
#define JSONCONS_TRAITS_EXTENSION_HPP
|
9
|
+
|
10
|
+
#include <stdexcept>
|
11
|
+
#include <string>
|
12
|
+
#include <cmath>
|
13
|
+
#include <type_traits> // std::enable_if, std::true_type
|
14
|
+
#include <memory>
|
15
|
+
#include <iterator> // std::iterator_traits
|
16
|
+
#include <exception>
|
17
|
+
#include <array> // std::array
|
18
|
+
#include <cstddef> // std::byte
|
19
|
+
#include <utility> // std::declval
|
20
|
+
#include <climits> // CHAR_BIT
|
21
|
+
#include <jsoncons/config/compiler_support.hpp>
|
22
|
+
|
23
|
+
namespace jsoncons {
|
24
|
+
namespace traits_extension {
|
25
|
+
|
26
|
+
// is_char8
|
27
|
+
template <typename CharT, typename Enable=void>
|
28
|
+
struct is_char8 : std::false_type {};
|
29
|
+
|
30
|
+
template <typename CharT>
|
31
|
+
struct is_char8<CharT, typename std::enable_if<std::is_integral<CharT>::value &&
|
32
|
+
!std::is_same<CharT,bool>::value &&
|
33
|
+
sizeof(uint8_t) == sizeof(CharT)>::type> : std::true_type {};
|
34
|
+
|
35
|
+
// is_char16
|
36
|
+
template <typename CharT, typename Enable=void>
|
37
|
+
struct is_char16 : std::false_type {};
|
38
|
+
|
39
|
+
template <typename CharT>
|
40
|
+
struct is_char16<CharT, typename std::enable_if<std::is_integral<CharT>::value &&
|
41
|
+
!std::is_same<CharT,bool>::value &&
|
42
|
+
(std::is_same<CharT,char16_t>::value || sizeof(uint16_t) == sizeof(CharT))>::type> : std::true_type {};
|
43
|
+
|
44
|
+
// is_char32
|
45
|
+
template <typename CharT, typename Enable=void>
|
46
|
+
struct is_char32 : std::false_type {};
|
47
|
+
|
48
|
+
template <typename CharT>
|
49
|
+
struct is_char32<CharT, typename std::enable_if<std::is_integral<CharT>::value &&
|
50
|
+
!std::is_same<CharT,bool>::value &&
|
51
|
+
(std::is_same<CharT,char32_t>::value || (!std::is_same<CharT,char16_t>::value && sizeof(uint32_t) == sizeof(CharT)))>::type> : std::true_type {};
|
52
|
+
|
53
|
+
// is_int128
|
54
|
+
|
55
|
+
template <class T, class Enable=void>
|
56
|
+
struct is_int128_type : std::false_type {};
|
57
|
+
|
58
|
+
#if defined(JSONCONS_HAS_INT128)
|
59
|
+
template <class T>
|
60
|
+
struct is_int128_type<T,typename std::enable_if<std::is_same<T,int128_type>::value>::type> : std::true_type {};
|
61
|
+
#endif
|
62
|
+
|
63
|
+
// is_unsigned_integer
|
64
|
+
|
65
|
+
template <class T, class Enable=void>
|
66
|
+
struct is_uint128_type : std::false_type {};
|
67
|
+
|
68
|
+
#if defined (JSONCONS_HAS_INT128)
|
69
|
+
template <class T>
|
70
|
+
struct is_uint128_type<T,typename std::enable_if<std::is_same<T,uint128_type>::value>::type> : std::true_type {};
|
71
|
+
#endif
|
72
|
+
|
73
|
+
template <class T, class Enable = void>
|
74
|
+
class integer_limits
|
75
|
+
{
|
76
|
+
public:
|
77
|
+
static constexpr bool is_specialized = false;
|
78
|
+
};
|
79
|
+
|
80
|
+
template <class T>
|
81
|
+
class integer_limits<T,typename std::enable_if<std::is_integral<T>::value && !std::is_same<T,bool>::value>::type>
|
82
|
+
{
|
83
|
+
public:
|
84
|
+
static constexpr bool is_specialized = true;
|
85
|
+
static constexpr bool is_signed = std::numeric_limits<T>::is_signed;
|
86
|
+
static constexpr int digits = std::numeric_limits<T>::digits;
|
87
|
+
static constexpr std::size_t buffer_size = static_cast<std::size_t>(sizeof(T)*CHAR_BIT*0.302) + 3;
|
88
|
+
|
89
|
+
static constexpr T(max)() noexcept
|
90
|
+
{
|
91
|
+
return (std::numeric_limits<T>::max)();
|
92
|
+
}
|
93
|
+
static constexpr T(min)() noexcept
|
94
|
+
{
|
95
|
+
return (std::numeric_limits<T>::min)();
|
96
|
+
}
|
97
|
+
static constexpr T lowest() noexcept
|
98
|
+
{
|
99
|
+
return std::numeric_limits<T>::lowest();
|
100
|
+
}
|
101
|
+
};
|
102
|
+
|
103
|
+
template <class T>
|
104
|
+
class integer_limits<T,typename std::enable_if<!std::is_integral<T>::value && is_int128_type<T>::value>::type>
|
105
|
+
{
|
106
|
+
public:
|
107
|
+
static constexpr bool is_specialized = true;
|
108
|
+
static constexpr bool is_signed = true;
|
109
|
+
static constexpr int digits = sizeof(T)*CHAR_BIT - 1;
|
110
|
+
static constexpr std::size_t buffer_size = (sizeof(T)*CHAR_BIT*0.302) + 3;
|
111
|
+
|
112
|
+
static constexpr T(max)() noexcept
|
113
|
+
{
|
114
|
+
return (((((T)1 << (digits - 1)) - 1) << 1) + 1);
|
115
|
+
}
|
116
|
+
static constexpr T(min)() noexcept
|
117
|
+
{
|
118
|
+
return -(max)() - 1;
|
119
|
+
}
|
120
|
+
static constexpr T lowest() noexcept
|
121
|
+
{
|
122
|
+
return (min)();
|
123
|
+
}
|
124
|
+
};
|
125
|
+
|
126
|
+
template <class T>
|
127
|
+
class integer_limits<T,typename std::enable_if<!std::is_integral<T>::value && is_uint128_type<T>::value>::type>
|
128
|
+
{
|
129
|
+
public:
|
130
|
+
static constexpr bool is_specialized = true;
|
131
|
+
static constexpr bool is_signed = false;
|
132
|
+
static constexpr int digits = sizeof(T)*CHAR_BIT;
|
133
|
+
|
134
|
+
static constexpr T(max)() noexcept
|
135
|
+
{
|
136
|
+
return T(T(~0));
|
137
|
+
}
|
138
|
+
static constexpr T(min)() noexcept
|
139
|
+
{
|
140
|
+
return 0;
|
141
|
+
}
|
142
|
+
static constexpr T lowest() noexcept
|
143
|
+
{
|
144
|
+
return std::numeric_limits<T>::lowest();
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
#ifndef JSONCONS_HAS_VOID_T
|
149
|
+
// follows https://en.cppreference.com/w/cpp/types/void_t
|
150
|
+
template<typename... Ts> struct make_void { typedef void type;};
|
151
|
+
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
|
152
|
+
#else
|
153
|
+
using void_t = std::void_t;
|
154
|
+
#endif
|
155
|
+
|
156
|
+
// follows http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
|
157
|
+
|
158
|
+
// detector
|
159
|
+
|
160
|
+
// primary template handles all types not supporting the archetypal Op
|
161
|
+
template<
|
162
|
+
class Default,
|
163
|
+
class, // always void; supplied externally
|
164
|
+
template<class...> class Op,
|
165
|
+
class... Args
|
166
|
+
>
|
167
|
+
struct detector
|
168
|
+
{
|
169
|
+
constexpr static auto value = false;
|
170
|
+
using type = Default;
|
171
|
+
};
|
172
|
+
|
173
|
+
// specialization recognizes and handles only types supporting Op
|
174
|
+
template<
|
175
|
+
class Default,
|
176
|
+
template<class...> class Op,
|
177
|
+
class... Args
|
178
|
+
>
|
179
|
+
struct detector<Default, void_t<Op<Args...>>, Op, Args...>
|
180
|
+
{
|
181
|
+
constexpr static auto value = true;
|
182
|
+
using type = Op<Args...>;
|
183
|
+
};
|
184
|
+
|
185
|
+
// is_detected, is_detected_t
|
186
|
+
|
187
|
+
template< template<class...> class Op, class... Args >
|
188
|
+
using
|
189
|
+
is_detected = detector<void, void, Op, Args...>;
|
190
|
+
|
191
|
+
template< template<class...> class Op, class... Args >
|
192
|
+
using
|
193
|
+
is_detected_t = typename is_detected<Op, Args...>::type;
|
194
|
+
|
195
|
+
// detected_or, detected_or_t
|
196
|
+
|
197
|
+
template< class Default, template<class...> class Op, class... Args >
|
198
|
+
using
|
199
|
+
detected_or = detector<Default, void, Op, Args...>;
|
200
|
+
|
201
|
+
template< class Default, template<class...> class Op, class... Args >
|
202
|
+
using
|
203
|
+
detected_or_t = typename detected_or<Default, Op, Args...>::type;
|
204
|
+
|
205
|
+
// is_detected_exact
|
206
|
+
|
207
|
+
template< class Expected, template<class...> class Op, class... Args >
|
208
|
+
using
|
209
|
+
is_detected_exact = std::is_same< Expected, is_detected_t<Op, Args...> >;
|
210
|
+
|
211
|
+
// is_detected_convertible
|
212
|
+
|
213
|
+
template< class To, template<class...> class Op, class... Args >
|
214
|
+
using
|
215
|
+
is_detected_convertible = std::is_convertible< is_detected_t<Op, Args...>, To >;
|
216
|
+
|
217
|
+
template <typename T>
|
218
|
+
struct is_stateless
|
219
|
+
: public std::integral_constant<bool,
|
220
|
+
(std::is_default_constructible<T>::value &&
|
221
|
+
std::is_empty<T>::value)>
|
222
|
+
{};
|
223
|
+
|
224
|
+
// to_plain_pointer
|
225
|
+
|
226
|
+
template<class Pointer> inline
|
227
|
+
typename std::pointer_traits<Pointer>::element_type* to_plain_pointer(Pointer ptr)
|
228
|
+
{
|
229
|
+
return (std::addressof(*ptr));
|
230
|
+
}
|
231
|
+
|
232
|
+
template<class T> inline
|
233
|
+
T * to_plain_pointer(T * ptr)
|
234
|
+
{
|
235
|
+
return (ptr);
|
236
|
+
}
|
237
|
+
|
238
|
+
// is_std_byte
|
239
|
+
|
240
|
+
template <class T, class Enable=void>
|
241
|
+
struct is_std_byte : std::false_type {};
|
242
|
+
#if defined(JSONCONS_HAS_STD_BYTE)
|
243
|
+
template <class T>
|
244
|
+
struct is_std_byte<T,
|
245
|
+
typename std::enable_if<std::is_same<T,std::byte>::value
|
246
|
+
>::type> : std::true_type {};
|
247
|
+
#endif
|
248
|
+
// is_byte
|
249
|
+
|
250
|
+
template <class T, class Enable=void>
|
251
|
+
struct is_byte : std::false_type {};
|
252
|
+
|
253
|
+
template <class T>
|
254
|
+
struct is_byte<T,
|
255
|
+
typename std::enable_if<std::is_same<T,char>::value ||
|
256
|
+
std::is_same<T,signed char>::value ||
|
257
|
+
std::is_same<T,unsigned char>::value ||
|
258
|
+
is_std_byte<T>::value
|
259
|
+
>::type> : std::true_type {};
|
260
|
+
|
261
|
+
// is_character
|
262
|
+
|
263
|
+
template <class T, class Enable=void>
|
264
|
+
struct is_character : std::false_type {};
|
265
|
+
|
266
|
+
template <class T>
|
267
|
+
struct is_character<T,
|
268
|
+
typename std::enable_if<std::is_same<T,char>::value ||
|
269
|
+
std::is_same<T,wchar_t>::value
|
270
|
+
>::type> : std::true_type {};
|
271
|
+
|
272
|
+
// is_narrow_character
|
273
|
+
|
274
|
+
template <class T, class Enable=void>
|
275
|
+
struct is_narrow_character : std::false_type {};
|
276
|
+
|
277
|
+
template <class T>
|
278
|
+
struct is_narrow_character<T,
|
279
|
+
typename std::enable_if<is_character<T>::value && (sizeof(T) == sizeof(char))
|
280
|
+
>::type> : std::true_type {};
|
281
|
+
|
282
|
+
// is_wide_character
|
283
|
+
|
284
|
+
template <class T, class Enable=void>
|
285
|
+
struct is_wide_character : std::false_type {};
|
286
|
+
|
287
|
+
template <class T>
|
288
|
+
struct is_wide_character<T,
|
289
|
+
typename std::enable_if<is_character<T>::value && (sizeof(T) != sizeof(char))
|
290
|
+
>::type> : std::true_type {};
|
291
|
+
|
292
|
+
// From boost
|
293
|
+
namespace ut_detail {
|
294
|
+
|
295
|
+
template<typename T>
|
296
|
+
struct is_cstring_impl : public std::false_type {};
|
297
|
+
|
298
|
+
template<typename T>
|
299
|
+
struct is_cstring_impl<T const*> : public is_cstring_impl<T*> {};
|
300
|
+
|
301
|
+
template<typename T>
|
302
|
+
struct is_cstring_impl<T const* const> : public is_cstring_impl<T*> {};
|
303
|
+
|
304
|
+
template<>
|
305
|
+
struct is_cstring_impl<char*> : public std::true_type {};
|
306
|
+
|
307
|
+
template<>
|
308
|
+
struct is_cstring_impl<wchar_t*> : public std::true_type {};
|
309
|
+
|
310
|
+
} // namespace ut_detail
|
311
|
+
|
312
|
+
template<typename T>
|
313
|
+
struct is_cstring : public ut_detail::is_cstring_impl<typename std::decay<T>::type> {};
|
314
|
+
|
315
|
+
// is_bool
|
316
|
+
|
317
|
+
template <class T, class Enable=void>
|
318
|
+
struct is_bool : std::false_type {};
|
319
|
+
|
320
|
+
template <class T>
|
321
|
+
struct is_bool<T,
|
322
|
+
typename std::enable_if<std::is_same<T,bool>::value
|
323
|
+
>::type> : std::true_type {};
|
324
|
+
|
325
|
+
// is_u8_u16_u32_or_u64
|
326
|
+
|
327
|
+
template <class T, class Enable=void>
|
328
|
+
struct is_u8_u16_u32_or_u64 : std::false_type {};
|
329
|
+
|
330
|
+
template <class T>
|
331
|
+
struct is_u8_u16_u32_or_u64<T,
|
332
|
+
typename std::enable_if<std::is_same<T,uint8_t>::value ||
|
333
|
+
std::is_same<T,uint16_t>::value ||
|
334
|
+
std::is_same<T,uint32_t>::value ||
|
335
|
+
std::is_same<T,uint64_t>::value
|
336
|
+
>::type> : std::true_type {};
|
337
|
+
|
338
|
+
// is_int
|
339
|
+
|
340
|
+
template <class T, class Enable=void>
|
341
|
+
struct is_i8_i16_i32_or_i64 : std::false_type {};
|
342
|
+
|
343
|
+
template <class T>
|
344
|
+
struct is_i8_i16_i32_or_i64<T,
|
345
|
+
typename std::enable_if<std::is_same<T,int8_t>::value ||
|
346
|
+
std::is_same<T,int16_t>::value ||
|
347
|
+
std::is_same<T,int32_t>::value ||
|
348
|
+
std::is_same<T,int64_t>::value
|
349
|
+
>::type> : std::true_type {};
|
350
|
+
|
351
|
+
// is_float_or_double
|
352
|
+
|
353
|
+
template <class T, class Enable=void>
|
354
|
+
struct is_float_or_double : std::false_type {};
|
355
|
+
|
356
|
+
template <class T>
|
357
|
+
struct is_float_or_double<T,
|
358
|
+
typename std::enable_if<std::is_same<T,float>::value ||
|
359
|
+
std::is_same<T,double>::value
|
360
|
+
>::type> : std::true_type {};
|
361
|
+
|
362
|
+
// make_unsigned
|
363
|
+
template <class T>
|
364
|
+
struct make_unsigned_impl {using type = typename std::make_unsigned<T>::type;};
|
365
|
+
|
366
|
+
#if defined(JSONCONS_HAS_INT128)
|
367
|
+
template <>
|
368
|
+
struct make_unsigned_impl<int128_type> {using type = uint128_type;};
|
369
|
+
template <>
|
370
|
+
struct make_unsigned_impl<uint128_type> {using type = uint128_type;};
|
371
|
+
#endif
|
372
|
+
|
373
|
+
template <class T>
|
374
|
+
struct make_unsigned
|
375
|
+
: make_unsigned_impl<typename std::remove_cv<T>::type>
|
376
|
+
{};
|
377
|
+
|
378
|
+
// is_integer
|
379
|
+
|
380
|
+
template <class T, class Enable=void>
|
381
|
+
struct is_integer : std::false_type {};
|
382
|
+
|
383
|
+
template <class T>
|
384
|
+
struct is_integer<T,typename std::enable_if<integer_limits<T>::is_specialized>::type> : std::true_type {};
|
385
|
+
|
386
|
+
// is_signed_integer
|
387
|
+
|
388
|
+
template <class T, class Enable=void>
|
389
|
+
struct is_signed_integer : std::false_type {};
|
390
|
+
|
391
|
+
template <class T>
|
392
|
+
struct is_signed_integer<T, typename std::enable_if<integer_limits<T>::is_specialized &&
|
393
|
+
integer_limits<T>::is_signed>::type> : std::true_type {};
|
394
|
+
|
395
|
+
// is_unsigned_integer
|
396
|
+
|
397
|
+
template <class T, class Enable=void>
|
398
|
+
struct is_unsigned_integer : std::false_type {};
|
399
|
+
|
400
|
+
template <class T>
|
401
|
+
struct is_unsigned_integer<T,
|
402
|
+
typename std::enable_if<integer_limits<T>::is_specialized &&
|
403
|
+
!integer_limits<T>::is_signed>::type> : std::true_type {};
|
404
|
+
|
405
|
+
// is_primitive
|
406
|
+
|
407
|
+
template <class T, class Enable=void>
|
408
|
+
struct is_primitive : std::false_type {};
|
409
|
+
|
410
|
+
template <class T>
|
411
|
+
struct is_primitive<T,
|
412
|
+
typename std::enable_if<is_integer<T>::value ||
|
413
|
+
is_bool<T>::value ||
|
414
|
+
std::is_floating_point<T>::value
|
415
|
+
>::type> : std::true_type {};
|
416
|
+
|
417
|
+
// Containers
|
418
|
+
|
419
|
+
template <class Container>
|
420
|
+
using
|
421
|
+
container_npos_t = decltype(Container::npos);
|
422
|
+
|
423
|
+
template <class Container>
|
424
|
+
using
|
425
|
+
container_allocator_type_t = typename Container::allocator_type;
|
426
|
+
|
427
|
+
template <class Container>
|
428
|
+
using
|
429
|
+
container_mapped_type_t = typename Container::mapped_type;
|
430
|
+
|
431
|
+
template <class Container>
|
432
|
+
using
|
433
|
+
container_key_type_t = typename Container::key_type;
|
434
|
+
|
435
|
+
template <class Container>
|
436
|
+
using
|
437
|
+
container_value_type_t = typename std::iterator_traits<typename Container::iterator>::value_type;
|
438
|
+
|
439
|
+
template <class Container>
|
440
|
+
using
|
441
|
+
container_char_traits_t = typename Container::traits_type::char_type;
|
442
|
+
|
443
|
+
template<class Container>
|
444
|
+
using
|
445
|
+
container_push_back_t = decltype(std::declval<Container>().push_back(std::declval<typename Container::value_type>()));
|
446
|
+
|
447
|
+
template<class Container>
|
448
|
+
using
|
449
|
+
container_push_front_t = decltype(std::declval<Container>().push_front(std::declval<typename Container::value_type>()));
|
450
|
+
|
451
|
+
template<class Container>
|
452
|
+
using
|
453
|
+
container_insert_t = decltype(std::declval<Container>().insert(std::declval<typename Container::value_type>()));
|
454
|
+
|
455
|
+
template<class Container>
|
456
|
+
using
|
457
|
+
container_reserve_t = decltype(std::declval<Container>().reserve(typename Container::size_type()));
|
458
|
+
|
459
|
+
template<class Container>
|
460
|
+
using
|
461
|
+
container_data_t = decltype(std::declval<Container>().data());
|
462
|
+
|
463
|
+
template<class Container>
|
464
|
+
using
|
465
|
+
container_size_t = decltype(std::declval<Container>().size());
|
466
|
+
|
467
|
+
// has_allocator_type
|
468
|
+
|
469
|
+
template <class T, class Enable=void>
|
470
|
+
struct has_allocator_type : std::false_type {};
|
471
|
+
|
472
|
+
template <class T>
|
473
|
+
struct has_allocator_type<T,
|
474
|
+
typename std::enable_if<is_detected<container_allocator_type_t,T>::value
|
475
|
+
>::type> : std::true_type {};
|
476
|
+
|
477
|
+
// is_string_or_string_view
|
478
|
+
|
479
|
+
template <class T, class Enable=void>
|
480
|
+
struct is_string_or_string_view : std::false_type {};
|
481
|
+
|
482
|
+
template <class T>
|
483
|
+
struct is_string_or_string_view<T,
|
484
|
+
typename std::enable_if<is_character<typename T::value_type>::value &&
|
485
|
+
is_detected_exact<typename T::value_type,container_char_traits_t,T>::value &&
|
486
|
+
is_detected<container_npos_t,T>::value
|
487
|
+
>::type> : std::true_type {};
|
488
|
+
|
489
|
+
// is_string
|
490
|
+
|
491
|
+
template <class T, class Enable=void>
|
492
|
+
struct is_string : std::false_type {};
|
493
|
+
|
494
|
+
template <class T>
|
495
|
+
struct is_string<T,
|
496
|
+
typename std::enable_if<is_string_or_string_view<T>::value &&
|
497
|
+
has_allocator_type<T>::value
|
498
|
+
>::type> : std::true_type {};
|
499
|
+
|
500
|
+
// is_string_view
|
501
|
+
|
502
|
+
template <class T, class Enable=void>
|
503
|
+
struct is_string_view : std::false_type {};
|
504
|
+
|
505
|
+
template <class T>
|
506
|
+
struct is_string_view<T,
|
507
|
+
typename std::enable_if<is_string_or_string_view<T>::value &&
|
508
|
+
!is_detected<container_allocator_type_t,T>::value
|
509
|
+
>::type> : std::true_type {};
|
510
|
+
|
511
|
+
// is_map_like
|
512
|
+
|
513
|
+
template <class T, class Enable=void>
|
514
|
+
struct is_map_like : std::false_type {};
|
515
|
+
|
516
|
+
template <class T>
|
517
|
+
struct is_map_like<T,
|
518
|
+
typename std::enable_if<is_detected<container_mapped_type_t,T>::value &&
|
519
|
+
is_detected<container_allocator_type_t,T>::value &&
|
520
|
+
is_detected<container_key_type_t,T>::value &&
|
521
|
+
is_detected<container_value_type_t,T>::value
|
522
|
+
>::type>
|
523
|
+
: std::true_type {};
|
524
|
+
|
525
|
+
// is_std_array
|
526
|
+
template<class T>
|
527
|
+
struct is_std_array : std::false_type {};
|
528
|
+
|
529
|
+
template<class E, std::size_t N>
|
530
|
+
struct is_std_array<std::array<E, N>> : std::true_type {};
|
531
|
+
|
532
|
+
// is_list_like
|
533
|
+
|
534
|
+
template <class T, class Enable=void>
|
535
|
+
struct is_list_like : std::false_type {};
|
536
|
+
|
537
|
+
template <class T>
|
538
|
+
struct is_list_like<T,
|
539
|
+
typename std::enable_if<is_detected<container_value_type_t,T>::value &&
|
540
|
+
is_detected<container_allocator_type_t,T>::value &&
|
541
|
+
!is_std_array<T>::value &&
|
542
|
+
!is_detected_exact<typename T::value_type,container_char_traits_t,T>::value &&
|
543
|
+
!is_map_like<T>::value
|
544
|
+
>::type>
|
545
|
+
: std::true_type {};
|
546
|
+
|
547
|
+
// is_constructible_from_const_pointer_and_size
|
548
|
+
|
549
|
+
template <class T, class Enable=void>
|
550
|
+
struct is_constructible_from_const_pointer_and_size : std::false_type {};
|
551
|
+
|
552
|
+
template <class T>
|
553
|
+
struct is_constructible_from_const_pointer_and_size<T,
|
554
|
+
typename std::enable_if<std::is_constructible<T,typename T::const_pointer,typename T::size_type>::value
|
555
|
+
>::type>
|
556
|
+
: std::true_type {};
|
557
|
+
|
558
|
+
// has_reserve
|
559
|
+
|
560
|
+
template<class Container>
|
561
|
+
using
|
562
|
+
has_reserve = is_detected<container_reserve_t, Container>;
|
563
|
+
|
564
|
+
// is_back_insertable
|
565
|
+
|
566
|
+
template<class Container>
|
567
|
+
using
|
568
|
+
is_back_insertable = is_detected<container_push_back_t, Container>;
|
569
|
+
|
570
|
+
// is_front_insertable
|
571
|
+
|
572
|
+
template<class Container>
|
573
|
+
using
|
574
|
+
is_front_insertable = is_detected<container_push_front_t, Container>;
|
575
|
+
|
576
|
+
// is_insertable
|
577
|
+
|
578
|
+
template<class Container>
|
579
|
+
using
|
580
|
+
is_insertable = is_detected<container_insert_t, Container>;
|
581
|
+
|
582
|
+
// has_data, has_data_exact
|
583
|
+
|
584
|
+
template<class Container>
|
585
|
+
using
|
586
|
+
has_data = is_detected<container_data_t, Container>;
|
587
|
+
|
588
|
+
template<class Ret, class Container>
|
589
|
+
using
|
590
|
+
has_data_exact = is_detected_exact<Ret, container_data_t, Container>;
|
591
|
+
|
592
|
+
// has_size
|
593
|
+
|
594
|
+
template<class Container>
|
595
|
+
using
|
596
|
+
has_size = is_detected<container_size_t, Container>;
|
597
|
+
|
598
|
+
// has_data_and_size
|
599
|
+
|
600
|
+
template<class Container>
|
601
|
+
struct has_data_and_size
|
602
|
+
{
|
603
|
+
static constexpr bool value = has_data<Container>::value && has_size<Container>::value;
|
604
|
+
};
|
605
|
+
|
606
|
+
// is_byte_sequence
|
607
|
+
|
608
|
+
template <class Container, class Enable=void>
|
609
|
+
struct is_byte_sequence : std::false_type {};
|
610
|
+
|
611
|
+
template <class Container>
|
612
|
+
struct is_byte_sequence<Container,
|
613
|
+
typename std::enable_if<has_data_exact<const typename Container::value_type*,const Container>::value &&
|
614
|
+
has_size<Container>::value &&
|
615
|
+
is_byte<typename Container::value_type>::value
|
616
|
+
>::type> : std::true_type {};
|
617
|
+
|
618
|
+
// is_char_sequence
|
619
|
+
|
620
|
+
template <class Container, class Enable=void>
|
621
|
+
struct is_char_sequence : std::false_type {};
|
622
|
+
|
623
|
+
template <class Container>
|
624
|
+
struct is_char_sequence<Container,
|
625
|
+
typename std::enable_if<has_data_exact<const typename Container::value_type*,const Container>::value &&
|
626
|
+
has_size<Container>::value &&
|
627
|
+
is_character<typename Container::value_type>::value
|
628
|
+
>::type> : std::true_type {};
|
629
|
+
|
630
|
+
// is_sequence_of
|
631
|
+
|
632
|
+
template <class Container, class ValueT, class Enable=void>
|
633
|
+
struct is_sequence_of : std::false_type {};
|
634
|
+
|
635
|
+
template <class Container, class ValueT>
|
636
|
+
struct is_sequence_of<Container,ValueT,
|
637
|
+
typename std::enable_if<has_data_exact<const typename Container::value_type*,const Container>::value &&
|
638
|
+
has_size<Container>::value &&
|
639
|
+
std::is_same<typename Container::value_type,ValueT>::value
|
640
|
+
>::type> : std::true_type {};
|
641
|
+
|
642
|
+
// is_back_insertable_byte_container
|
643
|
+
|
644
|
+
template <class Container, class Enable=void>
|
645
|
+
struct is_back_insertable_byte_container : std::false_type {};
|
646
|
+
|
647
|
+
template <class Container>
|
648
|
+
struct is_back_insertable_byte_container<Container,
|
649
|
+
typename std::enable_if<is_back_insertable<Container>::value &&
|
650
|
+
is_byte<typename Container::value_type>::value
|
651
|
+
>::type> : std::true_type {};
|
652
|
+
|
653
|
+
// is_back_insertable_char_container
|
654
|
+
|
655
|
+
template <class Container, class Enable=void>
|
656
|
+
struct is_back_insertable_char_container : std::false_type {};
|
657
|
+
|
658
|
+
template <class Container>
|
659
|
+
struct is_back_insertable_char_container<Container,
|
660
|
+
typename std::enable_if<is_back_insertable<Container>::value &&
|
661
|
+
is_character<typename Container::value_type>::value
|
662
|
+
>::type> : std::true_type {};
|
663
|
+
|
664
|
+
// is_back_insertable_container_of
|
665
|
+
|
666
|
+
template <class Container, class ValueT, class Enable=void>
|
667
|
+
struct is_back_insertable_container_of : std::false_type {};
|
668
|
+
|
669
|
+
template <class Container, class ValueT>
|
670
|
+
struct is_back_insertable_container_of<Container, ValueT,
|
671
|
+
typename std::enable_if<is_back_insertable<Container>::value &&
|
672
|
+
std::is_same<typename Container::value_type,ValueT>::value
|
673
|
+
>::type> : std::true_type {};
|
674
|
+
|
675
|
+
// is_c_array
|
676
|
+
|
677
|
+
template<class T>
|
678
|
+
struct is_c_array : std::false_type {};
|
679
|
+
|
680
|
+
template<class T>
|
681
|
+
struct is_c_array<T[]> : std::true_type {};
|
682
|
+
|
683
|
+
template<class T, std::size_t N>
|
684
|
+
struct is_c_array<T[N]> : std::true_type {};
|
685
|
+
|
686
|
+
namespace impl {
|
687
|
+
|
688
|
+
template<class C, class Enable=void>
|
689
|
+
struct is_typed_array : std::false_type {};
|
690
|
+
|
691
|
+
template<class T>
|
692
|
+
struct is_typed_array
|
693
|
+
<
|
694
|
+
T,
|
695
|
+
typename std::enable_if<is_list_like<T>::value &&
|
696
|
+
(std::is_same<typename std::decay<typename T::value_type>::type,uint8_t>::value ||
|
697
|
+
std::is_same<typename std::decay<typename T::value_type>::type,uint16_t>::value ||
|
698
|
+
std::is_same<typename std::decay<typename T::value_type>::type,uint32_t>::value ||
|
699
|
+
std::is_same<typename std::decay<typename T::value_type>::type,uint64_t>::value ||
|
700
|
+
std::is_same<typename std::decay<typename T::value_type>::type,int8_t>::value ||
|
701
|
+
std::is_same<typename std::decay<typename T::value_type>::type,int16_t>::value ||
|
702
|
+
std::is_same<typename std::decay<typename T::value_type>::type,int32_t>::value ||
|
703
|
+
std::is_same<typename std::decay<typename T::value_type>::type,int64_t>::value ||
|
704
|
+
std::is_same<typename std::decay<typename T::value_type>::type,float_t>::value ||
|
705
|
+
std::is_same<typename std::decay<typename T::value_type>::type,double_t>::value)>::type
|
706
|
+
> : std::true_type{};
|
707
|
+
|
708
|
+
} // namespace impl
|
709
|
+
|
710
|
+
template <typename T>
|
711
|
+
using is_typed_array = impl::is_typed_array<typename std::decay<T>::type>;
|
712
|
+
|
713
|
+
// is_compatible_element
|
714
|
+
|
715
|
+
template<class Container, class Element, class Enable=void>
|
716
|
+
struct is_compatible_element : std::false_type {};
|
717
|
+
|
718
|
+
template<class Container, class Element>
|
719
|
+
struct is_compatible_element
|
720
|
+
<
|
721
|
+
Container, Element,
|
722
|
+
typename std::enable_if<has_data<Container>::value>::type>
|
723
|
+
: std::is_convertible< typename std::remove_pointer<decltype(std::declval<Container>().data() )>::type(*)[], Element(*)[]>
|
724
|
+
{};
|
725
|
+
|
726
|
+
template<typename T>
|
727
|
+
using
|
728
|
+
construct_from_string_t = decltype(T(std::string{}));
|
729
|
+
|
730
|
+
|
731
|
+
template<class T>
|
732
|
+
using
|
733
|
+
is_constructible_from_string = is_detected<construct_from_string_t,T>;
|
734
|
+
|
735
|
+
template<typename T, typename Data, typename Size>
|
736
|
+
using
|
737
|
+
construct_from_data_size_t = decltype(T(static_cast<Data>(nullptr),Size{}));
|
738
|
+
|
739
|
+
|
740
|
+
template<class T, typename Data, typename Size>
|
741
|
+
using
|
742
|
+
is_constructible_from_data_size = is_detected<construct_from_data_size_t,T,Data,Size>;
|
743
|
+
|
744
|
+
// is_unary_function_object
|
745
|
+
// is_unary_function_object_exact
|
746
|
+
|
747
|
+
template<class FunctionObject, class Arg>
|
748
|
+
using
|
749
|
+
unary_function_object_t = decltype(std::declval<FunctionObject>()(std::declval<Arg>()));
|
750
|
+
|
751
|
+
template<class FunctionObject, class Arg>
|
752
|
+
using
|
753
|
+
is_unary_function_object = is_detected<unary_function_object_t, FunctionObject, Arg>;
|
754
|
+
|
755
|
+
template<class FunctionObject, class T, class Arg>
|
756
|
+
using
|
757
|
+
is_unary_function_object_exact = is_detected_exact<T,unary_function_object_t, FunctionObject, Arg>;
|
758
|
+
|
759
|
+
// is_binary_function_object
|
760
|
+
// is_binary_function_object_exact
|
761
|
+
|
762
|
+
template<class FunctionObject, class Arg1, class Arg2>
|
763
|
+
using
|
764
|
+
binary_function_object_t = decltype(std::declval<FunctionObject>()(std::declval<Arg1>(),std::declval<Arg2>()));
|
765
|
+
|
766
|
+
template<class FunctionObject, class Arg1, class Arg2>
|
767
|
+
using
|
768
|
+
is_binary_function_object = is_detected<binary_function_object_t, FunctionObject, Arg1, Arg2>;
|
769
|
+
|
770
|
+
template<class FunctionObject, class T, class Arg1, class Arg2>
|
771
|
+
using
|
772
|
+
is_binary_function_object_exact = is_detected_exact<T,binary_function_object_t, FunctionObject, Arg1, Arg2>;
|
773
|
+
|
774
|
+
template <class Source, class Enable=void>
|
775
|
+
struct is_convertible_to_string_view : std::false_type {};
|
776
|
+
|
777
|
+
template <class Source>
|
778
|
+
struct is_convertible_to_string_view<Source,typename std::enable_if<is_string_or_string_view<Source>::value ||
|
779
|
+
is_cstring<Source>::value
|
780
|
+
>::type> : std::true_type {};
|
781
|
+
|
782
|
+
#if defined(JSONCONS_HAS_2017)
|
783
|
+
template <typename T>
|
784
|
+
using is_nothrow_swappable = std::is_nothrow_swappable<T>;
|
785
|
+
#else
|
786
|
+
template <typename T>
|
787
|
+
struct is_nothrow_swappable {
|
788
|
+
static const bool value = noexcept(swap(std::declval<T&>(), std::declval<T&>()));
|
789
|
+
};
|
790
|
+
#endif
|
791
|
+
|
792
|
+
#if defined(JSONCONS_HAS_2014)
|
793
|
+
template <class T>
|
794
|
+
using alignment_of = std::alignment_of<T>;
|
795
|
+
|
796
|
+
template< class T, T... Ints >
|
797
|
+
using integer_sequence = std::integer_sequence<T,Ints...>;
|
798
|
+
|
799
|
+
template <T ... Inds>
|
800
|
+
using index_sequence = std::index_sequence<Inds...>;
|
801
|
+
|
802
|
+
template <class T, T N>
|
803
|
+
using make_integer_sequence = std::make_integer_sequence<T,N>;
|
804
|
+
|
805
|
+
template <std::size_t N>
|
806
|
+
using make_index_sequence = std::make_index_sequence<N>;
|
807
|
+
|
808
|
+
template<class... T>
|
809
|
+
using index_sequence_for = std::index_sequence_for<T...>;
|
810
|
+
|
811
|
+
#else
|
812
|
+
template <class T>
|
813
|
+
struct alignment_of
|
814
|
+
: std::integral_constant<std::size_t, alignof(typename std::remove_all_extents<T>::type)> {};
|
815
|
+
|
816
|
+
template <class T, T... Ints>
|
817
|
+
class integer_sequence
|
818
|
+
{
|
819
|
+
public:
|
820
|
+
using value_type = T;
|
821
|
+
static_assert(std::is_integral<value_type>::value, "not integral type");
|
822
|
+
static constexpr std::size_t size() noexcept
|
823
|
+
{
|
824
|
+
return sizeof...(Ints);
|
825
|
+
}
|
826
|
+
};
|
827
|
+
|
828
|
+
template <std::size_t... Inds>
|
829
|
+
using index_sequence = integer_sequence<std::size_t, Inds...>;
|
830
|
+
namespace detail_ {
|
831
|
+
template <class T, T Begin, T End, bool>
|
832
|
+
struct IntSeqImpl {
|
833
|
+
using TValue = T;
|
834
|
+
static_assert(std::is_integral<TValue>::value, "not integral type");
|
835
|
+
static_assert(Begin >= 0 && Begin < End, "unexpected argument (Begin<0 || Begin<=End)");
|
836
|
+
|
837
|
+
template <class, class>
|
838
|
+
struct IntSeqCombiner;
|
839
|
+
|
840
|
+
template <TValue... Inds0, TValue... Inds1>
|
841
|
+
struct IntSeqCombiner<integer_sequence<TValue, Inds0...>, integer_sequence<TValue, Inds1...>> {
|
842
|
+
using TResult = integer_sequence<TValue, Inds0..., Inds1...>;
|
843
|
+
};
|
844
|
+
|
845
|
+
using TResult =
|
846
|
+
typename IntSeqCombiner<typename IntSeqImpl<TValue, Begin, Begin + (End - Begin) / 2,
|
847
|
+
(End - Begin) / 2 == 1>::TResult,
|
848
|
+
typename IntSeqImpl<TValue, Begin + (End - Begin) / 2, End,
|
849
|
+
(End - Begin + 1) / 2 == 1>::TResult>::TResult;
|
850
|
+
};
|
851
|
+
|
852
|
+
template <class T, T Begin>
|
853
|
+
struct IntSeqImpl<T, Begin, Begin, false> {
|
854
|
+
using TValue = T;
|
855
|
+
static_assert(std::is_integral<TValue>::value, "not integral type");
|
856
|
+
static_assert(Begin >= 0, "unexpected argument (Begin<0)");
|
857
|
+
using TResult = integer_sequence<TValue>;
|
858
|
+
};
|
859
|
+
|
860
|
+
template <class T, T Begin, T End>
|
861
|
+
struct IntSeqImpl<T, Begin, End, true> {
|
862
|
+
using TValue = T;
|
863
|
+
static_assert(std::is_integral<TValue>::value, "not integral type");
|
864
|
+
static_assert(Begin >= 0, "unexpected argument (Begin<0)");
|
865
|
+
using TResult = integer_sequence<TValue, Begin>;
|
866
|
+
};
|
867
|
+
} // namespace detail_
|
868
|
+
|
869
|
+
template <class T, T N>
|
870
|
+
using make_integer_sequence = typename detail_::IntSeqImpl<T, 0, N, (N - 0) == 1>::TResult;
|
871
|
+
|
872
|
+
template <std::size_t N>
|
873
|
+
using make_index_sequence = make_integer_sequence<std::size_t, N>;
|
874
|
+
|
875
|
+
template <class... T>
|
876
|
+
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
877
|
+
|
878
|
+
|
879
|
+
#endif
|
880
|
+
|
881
|
+
} // traits_extension
|
882
|
+
} // jsoncons
|
883
|
+
|
884
|
+
#endif
|