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