]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/detail/config.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / json / detail / config.hpp
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/json
8 //
9
10 #ifndef BOOST_JSON_DETAIL_CONFIG_HPP
11 #define BOOST_JSON_DETAIL_CONFIG_HPP
12
13 #include <boost/config.hpp>
14 #include <boost/assert.hpp>
15 #include <boost/throw_exception.hpp>
16 #include <cstdint>
17 #include <type_traits>
18 #include <utility>
19
20 // detect 32/64 bit
21 #if UINTPTR_MAX == UINT64_MAX
22 # define BOOST_JSON_ARCH 64
23 #elif UINTPTR_MAX == UINT32_MAX
24 # define BOOST_JSON_ARCH 32
25 #else
26 # error Unknown or unsupported architecture, please open an issue
27 #endif
28
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]]
36 # else
37 # define BOOST_JSON_NODISCARD
38 # endif
39 # else
40 # define BOOST_JSON_NODISCARD
41 # endif
42 #endif
43
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]]
53 # endif
54 # endif
55 #endif
56
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]]
61 # endif
62 # endif
63 #endif
64
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]]
77 # endif
78 # elif defined(__has_cpp_attribute)
79 # if __has_cpp_attribute(noreturn)
80 # define BOOST_NORETURN [[noreturn]]
81 # endif
82 # endif
83 #endif
84
85 #ifndef BOOST_ASSERT
86 #define BOOST_ASSERT assert
87 #endif
88
89 #ifndef BOOST_STATIC_ASSERT
90 #define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
91 #endif
92
93 #ifndef BOOST_FALLTHROUGH
94 #define BOOST_FALLTHROUGH [[fallthrough]]
95 #endif
96
97 #ifndef BOOST_FORCEINLINE
98 # ifdef _MSC_VER
99 # define BOOST_FORCEINLINE __forceinline
100 # elif defined(__GNUC__) || defined(__clang__)
101 # define BOOST_FORCEINLINE inline __attribute__((always_inline))
102 # else
103 # define BOOST_FORCEINLINE inline
104 # endif
105 #endif
106
107 #ifndef BOOST_NOINLINE
108 # ifdef _MSC_VER
109 # define BOOST_NOINLINE __declspec(noinline)
110 # elif defined(__GNUC__) || defined(__clang__)
111 # define BOOST_NOINLINE __attribute__((noinline))
112 # else
113 # define BOOST_NOINLINE
114 # endif
115 #endif
116
117 #ifndef BOOST_THROW_EXCEPTION
118 # ifndef BOOST_NO_EXCEPTIONS
119 # define BOOST_THROW_EXCEPTION(x) throw(x)
120 # else
121 # define BOOST_THROW_EXCEPTION(x) do{}while(0)
122 # endif
123 #endif
124
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
130 # endif
131 #endif
132
133 #ifndef BOOST_SYMBOL_VISIBLE
134 #define BOOST_SYMBOL_VISIBLE
135 #endif
136
137 #if ! defined(BOOST_JSON_DOCS)
138 # define BOOST_JSON_NS_BEGIN \
139 namespace boost { \
140 namespace json {
141 # define BOOST_JSON_NS_END } }
142 #endif
143
144 #if defined(BOOST_JSON_DOCS)
145 # define BOOST_JSON_DECL
146 #else
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
152 # else
153 # define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
154 # define BOOST_JSON_CLASS_DECL BOOST_SYMBOL_IMPORT
155 # endif
156 # endif // shared lib
157 # ifndef BOOST_JSON_DECL
158 # define BOOST_JSON_DECL
159 # endif
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
164 # endif
165 # include <boost/config/auto_link.hpp>
166 # endif
167 #endif
168
169 #ifndef BOOST_JSON_DECL
170 #define BOOST_JSON_DECL
171 #endif
172 #ifndef BOOST_JSON_CLASS_DECL
173 #define BOOST_JSON_CLASS_DECL
174 #endif
175
176 #ifndef BOOST_JSON_LIKELY
177 # if defined(__GNUC__) || defined(__clang__)
178 # define BOOST_JSON_LIKELY(x) __builtin_expect(!!(x), 1)
179 # else
180 # define BOOST_JSON_LIKELY(x) x
181 # endif
182 #endif
183
184 #ifndef BOOST_JSON_UNLIKELY
185 # if defined(__GNUC__) || defined(__clang__)
186 # define BOOST_JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
187 # else
188 # define BOOST_JSON_UNLIKELY(x) x
189 # endif
190 #endif
191
192 #ifndef BOOST_JSON_UNREACHABLE
193 # define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
194 # ifdef _MSC_VER
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()
201 # endif
202 # endif
203 #endif
204
205 #ifndef BOOST_JSON_ASSUME
206 # define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
207 # ifdef _MSC_VER
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))
214 # endif
215 # endif
216 #endif
217
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
225 # endif
226 #endif
227
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
233 #endif
234 #ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
235 # define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
236 # define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
237 #endif
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
243 # else
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
248 // src.hpp.
249 # define BOOST_JSON_STACK_BUFFER_SIZE 256
250 # endif
251 #endif
252
253 BOOST_JSON_NS_BEGIN
254 namespace detail {
255
256 template<class...>
257 struct make_void
258 {
259 using type =void;
260 };
261
262 template<class... Ts>
263 using void_t = typename
264 make_void<Ts...>::type;
265
266 template<class T>
267 using remove_cvref = typename
268 std::remove_cv<typename
269 std::remove_reference<T>::type>::type;
270
271 template<class T, class U>
272 T exchange(T& t, U u) noexcept
273 {
274 T v = std::move(t);
275 t = std::move(u);
276 return v;
277 }
278
279 /* This is a derivative work, original copyright:
280
281 Copyright Eric Niebler 2013-present
282
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)
287
288 Project home: https://github.com/ericniebler/range-v3
289 */
290 template<typename T>
291 struct static_const
292 {
293 static constexpr T value {};
294 };
295 template<typename T>
296 constexpr T static_const<T>::value;
297
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_
302
303 } // detail
304 BOOST_JSON_NS_END
305
306 #endif