detail/config.hpp

100.0% Lines (4 / 4) 100.0% Functions (1 / 1, 1 excl)
config.hpp
f(x) Functions (2)
Line TLA Hits Source Code
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/config/pragma_message.hpp>
15 #include <boost/assert.hpp>
16 #include <boost/throw_exception.hpp>
17 #include <cstdint>
18 #include <type_traits>
19 #include <utility>
20
21 // detect 32/64 bit
22 #if UINTPTR_MAX == UINT64_MAX
23 # define BOOST_JSON_ARCH 64
24 #elif UINTPTR_MAX == UINT32_MAX
25 # define BOOST_JSON_ARCH 32
26 #else
27 # error Unknown or unsupported architecture, please open an issue
28 #endif
29
30 #ifndef BOOST_JSON_REQUIRE_CONST_INIT
31 # define BOOST_JSON_REQUIRE_CONST_INIT
32 # if __cpp_constinit >= 201907L
33 # undef BOOST_JSON_REQUIRE_CONST_INIT
34 # define BOOST_JSON_REQUIRE_CONST_INIT constinit
35 # elif defined(__clang__) && defined(__has_cpp_attribute)
36 # if __has_cpp_attribute(clang::require_constant_initialization)
37 # undef BOOST_JSON_REQUIRE_CONST_INIT
38 # define BOOST_JSON_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
39 # endif
40 # endif
41 #endif
42
43 #ifndef BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY
44 // clang, but not clang-cl
45 # if defined(__clang__) && !defined(_MSC_VER) && defined(__has_cpp_attribute)
46 # if __has_cpp_attribute(clang::no_destroy)
47 # define BOOST_JSON_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]]
48 # else
49 # define BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY
50 # endif
51 # else
52 # define BOOST_JSON_NO_ATTRIBUTE_NO_DESTROY
53 # endif
54 #endif
55
56 #if ! defined(BOOST_JSON_NO_SSE2) && \
57 ! defined(BOOST_JSON_USE_SSE2)
58 # if (defined(_M_IX86) && _M_IX86_FP == 2) || \
59 defined(_M_X64) || defined(__SSE2__)
60 # define BOOST_JSON_USE_SSE2
61 # endif
62 #endif
63
64 #if defined(BOOST_JSON_DOCS)
65 # define BOOST_JSON_DECL
66 #else
67 # if (defined(BOOST_JSON_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_JSON_STATIC_LINK)
68 # if defined(BOOST_JSON_SOURCE)
69 # define BOOST_JSON_DECL BOOST_SYMBOL_EXPORT
70 # else
71 # define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
72 # endif
73 # endif // shared lib
74 # ifndef BOOST_JSON_DECL
75 # define BOOST_JSON_DECL
76 # endif
77 # if !defined(BOOST_JSON_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_JSON_NO_LIB)
78 # define BOOST_LIB_NAME boost_json
79 # if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_JSON_DYN_LINK)
80 # define BOOST_DYN_LINK
81 # endif
82 # include <boost/config/auto_link.hpp>
83 # endif
84 #endif
85
86 #ifndef BOOST_JSON_LIKELY
87 # define BOOST_JSON_LIKELY(x) BOOST_LIKELY( !!(x) )
88 #endif
89
90 #ifndef BOOST_JSON_UNLIKELY
91 # define BOOST_JSON_UNLIKELY(x) BOOST_UNLIKELY( !!(x) )
92 #endif
93
94 #ifndef BOOST_JSON_UNREACHABLE
95 # ifdef _MSC_VER
96 # define BOOST_JSON_UNREACHABLE() __assume(0)
97 # elif defined(__GNUC__) || defined(__clang__)
98 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
99 # elif defined(__has_builtin)
100 # if __has_builtin(__builtin_unreachable)
101 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
102 # endif
103 # else
104 # define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
105 # endif
106 #endif
107
108 #ifndef BOOST_JSON_ASSUME
109 # define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
110 # ifdef _MSC_VER
111 # undef BOOST_JSON_ASSUME
112 # define BOOST_JSON_ASSUME(x) __assume(!!(x))
113 # elif defined(__has_builtin)
114 # if __has_builtin(__builtin_assume)
115 # undef BOOST_JSON_ASSUME
116 # define BOOST_JSON_ASSUME(x) __builtin_assume(!!(x))
117 # endif
118 # endif
119 #endif
120
121 // older versions of msvc and clang don't always
122 // constant initialize when they are supposed to
123 #ifndef BOOST_JSON_WEAK_CONSTINIT
124 # if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1920
125 # define BOOST_JSON_WEAK_CONSTINIT
126 # elif defined(__clang__) && __clang_major__ < 4
127 # define BOOST_JSON_WEAK_CONSTINIT
128 # endif
129 #endif
130
131 // These macros are private, for tests, do not change
132 // them or else previously built libraries won't match.
133 #ifndef BOOST_JSON_MAX_STRING_SIZE
134 # define BOOST_JSON_NO_MAX_STRING_SIZE
135 # define BOOST_JSON_MAX_STRING_SIZE 0x7ffffffe
136 #endif
137 #ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
138 # define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
139 # define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
140 #endif
141 #ifndef BOOST_JSON_STACK_BUFFER_SIZE
142 # define BOOST_JSON_NO_STACK_BUFFER_SIZE
143 # if defined(__i386__) || defined(__x86_64__) || \
144 defined(_M_IX86) || defined(_M_X64)
145 # define BOOST_JSON_STACK_BUFFER_SIZE 4096
146 # else
147 // If we are not on Intel, then assume we are on
148 // embedded and use a smaller stack size. If this
149 // is not suitable, the user can define the macro
150 // themselves when building the library or including
151 // src.hpp.
152 # define BOOST_JSON_STACK_BUFFER_SIZE 256
153 # endif
154 #endif
155
156 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
157 # define BOOST_JSON_CONSTINIT constinit
158 #elif defined(__has_cpp_attribute) && defined(__clang__)
159 # if __has_cpp_attribute(clang::require_constant_initialization)
160 # define BOOST_JSON_CONSTINIT [[clang::require_constant_initialization]]
161 # endif
162 #elif defined(__GNUC__) && (__GNUC__ >= 10)
163 # define BOOST_JSON_CONSTINIT __constinit
164 #endif
165 #ifndef BOOST_JSON_CONSTINIT
166 # define BOOST_JSON_CONSTINIT
167 #endif
168
169 namespace boost {
170 namespace json {
171 namespace detail {
172
173 template<class...>
174 struct make_void
175 {
176 using type =void;
177 };
178
179 template<class... Ts>
180 using void_t = typename
181 make_void<Ts...>::type;
182
183 template<class T>
184 using remove_cvref = typename
185 std::remove_cv<typename
186 std::remove_reference<T>::type>::type;
187
188 template<class T, class U>
189 25058792x T exchange(T& t, U u) noexcept
190 {
191 25058792x T v = std::move(t);
192 25058792x t = std::move(u);
193 25058792x return v;
194 }
195
196 /* This is a derivative work, original copyright:
197
198 Copyright Eric Niebler 2013-present
199
200 Use, modification and distribution is subject to the
201 Boost Software License, Version 1.0. (See accompanying
202 file LICENSE_1_0.txt or copy at
203 http://www.boost.org/LICENSE_1_0.txt)
204
205 Project home: https://github.com/ericniebler/range-v3
206 */
207 template<typename T>
208 struct static_const
209 {
210 static constexpr T value {};
211 };
212 template<typename T>
213 constexpr T static_const<T>::value;
214
215 #define BOOST_JSON_INLINE_VARIABLE(name, type) \
216 namespace { constexpr auto& name = \
217 ::boost::json::detail::static_const<type>::value; \
218 } struct _unused_ ## name ## _semicolon_bait_
219
220 } // detail
221 } // namespace json
222 } // namespace boost
223
224 #ifndef BOOST_JSON_ALLOW_DEPRECATED
225 # ifdef BOOST_ALLOW_DEPRECATED
226 # define BOOST_JSON_ALLOW_DEPRECATED
227 # endif
228 #endif
229
230 #if defined(BOOST_GCC) && BOOST_GCC < 50000 && !defined(BOOST_JSON_ALLOW_DEPRECATED)
231 # pragma GCC warning "Support for GCC versions below 5.0 is deprecated and will stop in Boost 1.88.0. To suppress this message define macro BOOST_JSON_ALLOW_DEPRECATED."
232 #endif
233
234 #ifndef BOOST_JSON_ALLOW_DEPRECATED
235 # define BOOST_JSON_DEPRECATED(x) BOOST_DEPRECATED(x)
236 #else
237 # define BOOST_JSON_DEPRECATED(x)
238 #endif
239
240 #ifndef BOOST_ALL_NO_EMBEDDED_GDB_SCRIPTS
241 #include <boost/json/detail/gdb_printers.hpp>
242 #endif
243
244 #endif
245