config.hpp
9.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/json
//
#ifndef BOOST_JSON_DETAIL_CONFIG_HPP
#define BOOST_JSON_DETAIL_CONFIG_HPP
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <cstdint>
#include <type_traits>
#include <utility>
// detect 32/64 bit
#if UINTPTR_MAX == UINT64_MAX
# define BOOST_JSON_ARCH 64
#elif UINTPTR_MAX == UINT32_MAX
# define BOOST_JSON_ARCH 32
#else
# error Unknown or unsupported architecture, please open an issue
#endif
// VFALCO Copied from Boost.Config
// This is a derivative work.
#ifndef BOOST_JSON_NODISCARD
# ifdef __has_cpp_attribute
// clang-6 accepts [[nodiscard]] with -std=c++14, but warns about it -pedantic
# if __has_cpp_attribute(nodiscard) && !(defined(__clang__) && (__cplusplus < 201703L))
# define BOOST_JSON_NODISCARD [[nodiscard]]
# else
# define BOOST_JSON_NODISCARD
# endif
# else
# define BOOST_JSON_NODISCARD
# endif
#endif
#ifndef BOOST_JSON_REQUIRE_CONST_INIT
# define BOOST_JSON_REQUIRE_CONST_INIT
# if __cpp_constinit >= 201907L
# undef BOOST_JSON_REQUIRE_CONST_INIT
# define BOOST_JSON_REQUIRE_CONST_INIT constinit
# elif defined(__clang__) && defined(__has_cpp_attribute)
# if __has_cpp_attribute(clang::require_constant_initialization)
# undef BOOST_JSON_REQUIRE_CONST_INIT
# define BOOST_JSON_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
# endif
# endif
#endif
#ifndef BOOST_JSON_NO_DESTROY
# if defined(__clang__) && defined(__has_cpp_attribute)
# if __has_cpp_attribute(clang::no_destroy)
# define BOOST_JSON_NO_DESTROY [[clang::no_destroy]]
# endif
# endif
#endif
// BOOST_NORETURN ---------------------------------------------//
// Macro to use before a function declaration/definition to designate
// the function as not returning normally (i.e. with a return statement
// or by leaving the function scope, if the function return type is void).
#if !defined(BOOST_NORETURN)
# if defined(_MSC_VER)
# define BOOST_NORETURN __declspec(noreturn)
# elif defined(__GNUC__)
# define BOOST_NORETURN __attribute__ ((__noreturn__))
# elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130)
# if __has_attribute(noreturn)
# define BOOST_NORETURN [[noreturn]]
# endif
# elif defined(__has_cpp_attribute)
# if __has_cpp_attribute(noreturn)
# define BOOST_NORETURN [[noreturn]]
# endif
# endif
#endif
#ifndef BOOST_ASSERT
#define BOOST_ASSERT assert
#endif
#ifndef BOOST_STATIC_ASSERT
#define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
#endif
#ifndef BOOST_FALLTHROUGH
#define BOOST_FALLTHROUGH [[fallthrough]]
#endif
#ifndef BOOST_FORCEINLINE
# ifdef _MSC_VER
# define BOOST_FORCEINLINE __forceinline
# elif defined(__GNUC__) || defined(__clang__)
# define BOOST_FORCEINLINE inline __attribute__((always_inline))
# else
# define BOOST_FORCEINLINE inline
# endif
#endif
#ifndef BOOST_NOINLINE
# ifdef _MSC_VER
# define BOOST_NOINLINE __declspec(noinline)
# elif defined(__GNUC__) || defined(__clang__)
# define BOOST_NOINLINE __attribute__((noinline))
# else
# define BOOST_NOINLINE
# endif
#endif
#ifndef BOOST_THROW_EXCEPTION
# ifndef BOOST_NO_EXCEPTIONS
# define BOOST_THROW_EXCEPTION(x) throw(x)
# else
# define BOOST_THROW_EXCEPTION(x) do{}while(0)
# endif
#endif
#if ! defined(BOOST_JSON_NO_SSE2) && \
! defined(BOOST_JSON_USE_SSE2)
# if (defined(_M_IX86) && _M_IX86_FP == 2) || \
defined(_M_X64) || defined(__SSE2__)
# define BOOST_JSON_USE_SSE2
# endif
#endif
#ifndef BOOST_SYMBOL_VISIBLE
#define BOOST_SYMBOL_VISIBLE
#endif
#if ! defined(BOOST_JSON_DOCS)
# define BOOST_JSON_NS_BEGIN \
namespace boost { \
namespace json {
# define BOOST_JSON_NS_END } }
#endif
#if defined(BOOST_JSON_DOCS)
# define BOOST_JSON_DECL
#else
# if (defined(BOOST_JSON_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_JSON_STATIC_LINK)
# if defined(BOOST_JSON_SOURCE)
# define BOOST_JSON_DECL BOOST_SYMBOL_EXPORT
# define BOOST_JSON_CLASS_DECL BOOST_SYMBOL_EXPORT
# define BOOST_JSON_BUILD_DLL
# else
# define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
# define BOOST_JSON_CLASS_DECL BOOST_SYMBOL_IMPORT
# endif
# endif // shared lib
# ifndef BOOST_JSON_DECL
# define BOOST_JSON_DECL
# endif
# if !defined(BOOST_JSON_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_JSON_NO_LIB)
# define BOOST_LIB_NAME boost_json
# if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_JSON_DYN_LINK)
# define BOOST_DYN_LINK
# endif
# include <boost/config/auto_link.hpp>
# endif
#endif
#ifndef BOOST_JSON_DECL
#define BOOST_JSON_DECL
#endif
#ifndef BOOST_JSON_CLASS_DECL
#define BOOST_JSON_CLASS_DECL
#endif
#ifndef BOOST_JSON_LIKELY
# if defined(__GNUC__) || defined(__clang__)
# define BOOST_JSON_LIKELY(x) __builtin_expect(!!(x), 1)
# else
# define BOOST_JSON_LIKELY(x) x
# endif
#endif
#ifndef BOOST_JSON_UNLIKELY
# if defined(__GNUC__) || defined(__clang__)
# define BOOST_JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
# else
# define BOOST_JSON_UNLIKELY(x) x
# endif
#endif
#ifndef BOOST_JSON_UNREACHABLE
# ifdef _MSC_VER
# define BOOST_JSON_UNREACHABLE() __assume(0)
# elif defined(__GNUC__) || defined(__clang__)
# define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
# elif defined(__has_builtin)
# if __has_builtin(__builtin_unreachable)
# define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
# endif
# else
# define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
# endif
#endif
#ifndef BOOST_JSON_ASSUME
# define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
# ifdef _MSC_VER
# undef BOOST_JSON_ASSUME
# define BOOST_JSON_ASSUME(x) __assume(!!(x))
# elif defined(__has_builtin)
# if __has_builtin(__builtin_assume)
# undef BOOST_JSON_ASSUME
# define BOOST_JSON_ASSUME(x) __builtin_assume(!!(x))
# endif
# endif
#endif
// older versions of msvc and clang don't always
// constant initialize when they are supposed to
#ifndef BOOST_JSON_WEAK_CONSTINIT
# if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1920
# define BOOST_JSON_WEAK_CONSTINIT
# elif defined(__clang__) && __clang_major__ < 4
# define BOOST_JSON_WEAK_CONSTINIT
# endif
#endif
// These macros are private, for tests, do not change
// them or else previously built libraries won't match.
#ifndef BOOST_JSON_MAX_STRING_SIZE
# define BOOST_JSON_NO_MAX_STRING_SIZE
# define BOOST_JSON_MAX_STRING_SIZE 0x7ffffffe
#endif
#ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
# define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
# define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
#endif
#ifndef BOOST_JSON_STACK_BUFFER_SIZE
# define BOOST_JSON_NO_STACK_BUFFER_SIZE
# if defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64)
# define BOOST_JSON_STACK_BUFFER_SIZE 4096
# else
// If we are not on Intel, then assume we are on
// embedded and use a smaller stack size. If this
// is not suitable, the user can define the macro
// themselves when building the library or including
// src.hpp.
# define BOOST_JSON_STACK_BUFFER_SIZE 256
# endif
#endif
#if ! defined(BOOST_JSON_BIG_ENDIAN) && ! defined(BOOST_JSON_LITTLE_ENDIAN)
// Copied from Boost.Endian
# if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define BOOST_JSON_LITTLE_ENDIAN
# elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define BOOST_JSON_BIG_ENDIAN
# elif defined(__LITTLE_ENDIAN__)
# define BOOST_JSON_LITTLE_ENDIAN
# elif defined(__BIG_ENDIAN__)
# define BOOST_JSON_BIG_ENDIAN
# elif defined(_MSC_VER) || defined(__i386__) || defined(__x86_64__)
# define BOOST_JSON_LITTLE_ENDIAN
# else
# error The Boost.JSON library could not determine the endianness of this platform. Define either BOOST_JSON_BIG_ENDIAN or BOOST_JSON_LITTLE_ENDIAN.
# endif
#endif
BOOST_JSON_NS_BEGIN
namespace detail {
template<class...>
struct make_void
{
using type =void;
};
template<class... Ts>
using void_t = typename
make_void<Ts...>::type;
template<class T>
using remove_cvref = typename
std::remove_cv<typename
std::remove_reference<T>::type>::type;
template<class T, class U>
T exchange(T& t, U u) noexcept
{
T v = std::move(t);
t = std::move(u);
return v;
}
/* This is a derivative work, original copyright:
Copyright Eric Niebler 2013-present
Use, modification and distribution is subject to the
Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
Project home: https://github.com/ericniebler/range-v3
*/
template<typename T>
struct static_const
{
static constexpr T value {};
};
template<typename T>
constexpr T static_const<T>::value;
#define BOOST_JSON_INLINE_VARIABLE(name, type) \
namespace { constexpr auto& name = \
::boost::json::detail::static_const<type>::value; \
} struct _unused_ ## name ## _semicolon_bait_
} // detail
BOOST_JSON_NS_END
#endif