2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/json
10 #ifndef BOOST_JSON_DETAIL_CONFIG_HPP
11 #define BOOST_JSON_DETAIL_CONFIG_HPP
13 #include <boost/config.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/throw_exception.hpp>
17 #include <type_traits>
21 #if UINTPTR_MAX == UINT64_MAX
22 # define BOOST_JSON_ARCH 64
23 #elif UINTPTR_MAX == UINT32_MAX
24 # define BOOST_JSON_ARCH 32
26 # error Unknown or unsupported architecture, please open an issue
29 // VFALCO Copied from Boost.Config
30 // This is a derivative work.
31 #ifndef BOOST_JSON_NODISCARD
32 # ifdef __has_cpp_attribute
33 // clang-6 accepts [[nodiscard]] with -std=c++14, but warns about it -pedantic
34 # if __has_cpp_attribute(nodiscard) && !(defined(__clang__) && (__cplusplus < 201703L))
35 # define BOOST_JSON_NODISCARD [[nodiscard]]
37 # define BOOST_JSON_NODISCARD
40 # define BOOST_JSON_NODISCARD
44 #ifndef BOOST_JSON_REQUIRE_CONST_INIT
45 # define BOOST_JSON_REQUIRE_CONST_INIT
46 # if __cpp_constinit >= 201907L
47 # undef BOOST_JSON_REQUIRE_CONST_INIT
48 # define BOOST_JSON_REQUIRE_CONST_INIT constinit
49 # elif defined(__clang__) && defined(__has_cpp_attribute)
50 # if __has_cpp_attribute(clang::require_constant_initialization)
51 # undef BOOST_JSON_REQUIRE_CONST_INIT
52 # define BOOST_JSON_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
57 #ifndef BOOST_JSON_NO_DESTROY
58 # if defined(__clang__) && defined(__has_cpp_attribute)
59 # if __has_cpp_attribute(clang::no_destroy)
60 # define BOOST_JSON_NO_DESTROY [[clang::no_destroy]]
65 // BOOST_NORETURN ---------------------------------------------//
66 // Macro to use before a function declaration/definition to designate
67 // the function as not returning normally (i.e. with a return statement
68 // or by leaving the function scope, if the function return type is void).
69 #if !defined(BOOST_NORETURN)
70 # if defined(_MSC_VER)
71 # define BOOST_NORETURN __declspec(noreturn)
72 # elif defined(__GNUC__)
73 # define BOOST_NORETURN __attribute__ ((__noreturn__))
74 # elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130)
75 # if __has_attribute(noreturn)
76 # define BOOST_NORETURN [[noreturn]]
78 # elif defined(__has_cpp_attribute)
79 # if __has_cpp_attribute(noreturn)
80 # define BOOST_NORETURN [[noreturn]]
86 #define BOOST_ASSERT assert
89 #ifndef BOOST_STATIC_ASSERT
90 #define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
93 #ifndef BOOST_FALLTHROUGH
94 #define BOOST_FALLTHROUGH [[fallthrough]]
97 #ifndef BOOST_FORCEINLINE
99 # define BOOST_FORCEINLINE __forceinline
100 # elif defined(__GNUC__) || defined(__clang__)
101 # define BOOST_FORCEINLINE inline __attribute__((always_inline))
103 # define BOOST_FORCEINLINE inline
107 #ifndef BOOST_NOINLINE
109 # define BOOST_NOINLINE __declspec(noinline)
110 # elif defined(__GNUC__) || defined(__clang__)
111 # define BOOST_NOINLINE __attribute__((noinline))
113 # define BOOST_NOINLINE
117 #ifndef BOOST_THROW_EXCEPTION
118 # ifndef BOOST_NO_EXCEPTIONS
119 # define BOOST_THROW_EXCEPTION(x) throw(x)
121 # define BOOST_THROW_EXCEPTION(x) do{}while(0)
125 #if ! defined(BOOST_JSON_NO_SSE2) && \
126 ! defined(BOOST_JSON_USE_SSE2)
127 # if (defined(_M_IX86) && _M_IX86_FP == 2) || \
128 defined(_M_X64) || defined(__SSE2__)
129 # define BOOST_JSON_USE_SSE2
133 #ifndef BOOST_SYMBOL_VISIBLE
134 #define BOOST_SYMBOL_VISIBLE
137 #if ! defined(BOOST_JSON_DOCS)
138 # define BOOST_JSON_NS_BEGIN \
141 # define BOOST_JSON_NS_END } }
144 #if defined(BOOST_JSON_DOCS)
145 # define BOOST_JSON_DECL
147 # if (defined(BOOST_JSON_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_JSON_STATIC_LINK)
148 # if defined(BOOST_JSON_SOURCE)
149 # define BOOST_JSON_DECL BOOST_SYMBOL_EXPORT
150 # define BOOST_JSON_CLASS_DECL BOOST_SYMBOL_EXPORT
151 # define BOOST_JSON_BUILD_DLL
153 # define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
154 # define BOOST_JSON_CLASS_DECL BOOST_SYMBOL_IMPORT
156 # endif // shared lib
157 # ifndef BOOST_JSON_DECL
158 # define BOOST_JSON_DECL
160 # if !defined(BOOST_JSON_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_JSON_NO_LIB)
161 # define BOOST_LIB_NAME boost_json
162 # if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_JSON_DYN_LINK)
163 # define BOOST_DYN_LINK
165 # include <boost/config/auto_link.hpp>
169 #ifndef BOOST_JSON_DECL
170 #define BOOST_JSON_DECL
172 #ifndef BOOST_JSON_CLASS_DECL
173 #define BOOST_JSON_CLASS_DECL
176 #ifndef BOOST_JSON_LIKELY
177 # if defined(__GNUC__) || defined(__clang__)
178 # define BOOST_JSON_LIKELY(x) __builtin_expect(!!(x), 1)
180 # define BOOST_JSON_LIKELY(x) x
184 #ifndef BOOST_JSON_UNLIKELY
185 # if defined(__GNUC__) || defined(__clang__)
186 # define BOOST_JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
188 # define BOOST_JSON_UNLIKELY(x) x
192 #ifndef BOOST_JSON_UNREACHABLE
193 # define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
195 # undef BOOST_JSON_UNREACHABLE
196 # define BOOST_JSON_UNREACHABLE() __assume(0)
197 # elif defined(__has_builtin)
198 # if __has_builtin(__builtin_unreachable)
199 # undef BOOST_JSON_UNREACHABLE
200 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
205 #ifndef BOOST_JSON_ASSUME
206 # define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
208 # undef BOOST_JSON_ASSUME
209 # define BOOST_JSON_ASSUME(x) __assume(!!(x))
210 # elif defined(__has_builtin)
211 # if __has_builtin(__builtin_assume)
212 # undef BOOST_JSON_ASSUME
213 # define BOOST_JSON_ASSUME(x) __builtin_assume(!!(x))
218 // older versions of msvc and clang don't always
219 // constant initialize when they are supposed to
220 #ifndef BOOST_JSON_WEAK_CONSTINIT
221 # if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1920
222 # define BOOST_JSON_WEAK_CONSTINIT
223 # elif defined(__clang__) && __clang_major__ < 4
224 # define BOOST_JSON_WEAK_CONSTINIT
228 // These macros are private, for tests, do not change
229 // them or else previously built libraries won't match.
230 #ifndef BOOST_JSON_MAX_STRING_SIZE
231 # define BOOST_JSON_NO_MAX_STRING_SIZE
232 # define BOOST_JSON_MAX_STRING_SIZE 0x7ffffffe
234 #ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
235 # define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
236 # define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
238 #ifndef BOOST_JSON_STACK_BUFFER_SIZE
239 # define BOOST_JSON_NO_STACK_BUFFER_SIZE
240 # if defined(__i386__) || defined(__x86_64__) || \
241 defined(_M_IX86) || defined(_M_X64)
242 # define BOOST_JSON_STACK_BUFFER_SIZE 4096
244 // If we are not on Intel, then assume we are on
245 // embedded and use a smaller stack size. If this
246 // is not suitable, the user can define the macro
247 // themselves when building the library or including
249 # define BOOST_JSON_STACK_BUFFER_SIZE 256
262 template<class... Ts>
263 using void_t = typename
264 make_void<Ts...>::type;
267 using remove_cvref = typename
268 std::remove_cv<typename
269 std::remove_reference<T>::type>::type;
271 template<class T, class U>
272 T exchange(T& t, U u) noexcept
279 /* This is a derivative work, original copyright:
281 Copyright Eric Niebler 2013-present
283 Use, modification and distribution is subject to the
284 Boost Software License, Version 1.0. (See accompanying
285 file LICENSE_1_0.txt or copy at
286 http://www.boost.org/LICENSE_1_0.txt)
288 Project home: https://github.com/ericniebler/range-v3
293 static constexpr T value {};
296 constexpr T static_const<T>::value;
298 #define BOOST_JSON_INLINE_VARIABLE(name, type) \
299 namespace { constexpr auto& name = \
300 ::boost::json::detail::static_const<type>::value; \
301 } struct _unused_ ## name ## _semicolon_bait_