File indexing completed on 2024-11-15 09:14:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_DETAIL_CONFIG_HPP
0011 #define BOOST_JSON_DETAIL_CONFIG_HPP
0012
0013 #include <boost/config.hpp>
0014 #include <boost/assert.hpp>
0015 #include <boost/throw_exception.hpp>
0016 #include <cstdint>
0017 #include <type_traits>
0018 #include <utility>
0019
0020
0021 #if UINTPTR_MAX == UINT64_MAX
0022 # define BOOST_JSON_ARCH 64
0023 #elif UINTPTR_MAX == UINT32_MAX
0024 # define BOOST_JSON_ARCH 32
0025 #else
0026 # error Unknown or unsupported architecture, please open an issue
0027 #endif
0028
0029
0030
0031 #ifndef BOOST_JSON_NODISCARD
0032 # ifdef __has_cpp_attribute
0033
0034 # if __has_cpp_attribute(nodiscard) && !(defined(__clang__) && (__cplusplus < 201703L))
0035 # define BOOST_JSON_NODISCARD [[nodiscard]]
0036 # else
0037 # define BOOST_JSON_NODISCARD
0038 # endif
0039 # else
0040 # define BOOST_JSON_NODISCARD
0041 # endif
0042 #endif
0043
0044 #ifndef BOOST_JSON_REQUIRE_CONST_INIT
0045 # define BOOST_JSON_REQUIRE_CONST_INIT
0046 # if __cpp_constinit >= 201907L
0047 # undef BOOST_JSON_REQUIRE_CONST_INIT
0048 # define BOOST_JSON_REQUIRE_CONST_INIT constinit
0049 # elif defined(__clang__) && defined(__has_cpp_attribute)
0050 # if __has_cpp_attribute(clang::require_constant_initialization)
0051 # undef BOOST_JSON_REQUIRE_CONST_INIT
0052 # define BOOST_JSON_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
0053 # endif
0054 # endif
0055 #endif
0056
0057 #ifndef BOOST_JSON_NO_DESTROY
0058 # if defined(__clang__) && defined(__has_cpp_attribute)
0059 # if __has_cpp_attribute(clang::no_destroy)
0060 # define BOOST_JSON_NO_DESTROY [[clang::no_destroy]]
0061 # endif
0062 # endif
0063 #endif
0064
0065
0066
0067
0068
0069 #if !defined(BOOST_NORETURN)
0070 # if defined(_MSC_VER)
0071 # define BOOST_NORETURN __declspec(noreturn)
0072 # elif defined(__GNUC__)
0073 # define BOOST_NORETURN __attribute__ ((__noreturn__))
0074 # elif defined(__has_attribute) && defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x5130)
0075 # if __has_attribute(noreturn)
0076 # define BOOST_NORETURN [[noreturn]]
0077 # endif
0078 # elif defined(__has_cpp_attribute)
0079 # if __has_cpp_attribute(noreturn)
0080 # define BOOST_NORETURN [[noreturn]]
0081 # endif
0082 # endif
0083 #endif
0084
0085 #ifndef BOOST_ASSERT
0086 #define BOOST_ASSERT assert
0087 #endif
0088
0089 #ifndef BOOST_STATIC_ASSERT
0090 #define BOOST_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
0091 #endif
0092
0093 #ifndef BOOST_FALLTHROUGH
0094 #define BOOST_FALLTHROUGH [[fallthrough]]
0095 #endif
0096
0097 #ifndef BOOST_FORCEINLINE
0098 # ifdef _MSC_VER
0099 # define BOOST_FORCEINLINE __forceinline
0100 # elif defined(__GNUC__) || defined(__clang__)
0101 # define BOOST_FORCEINLINE inline __attribute__((always_inline))
0102 # else
0103 # define BOOST_FORCEINLINE inline
0104 # endif
0105 #endif
0106
0107 #ifndef BOOST_NOINLINE
0108 # ifdef _MSC_VER
0109 # define BOOST_NOINLINE __declspec(noinline)
0110 # elif defined(__GNUC__) || defined(__clang__)
0111 # define BOOST_NOINLINE __attribute__((noinline))
0112 # else
0113 # define BOOST_NOINLINE
0114 # endif
0115 #endif
0116
0117 #ifndef BOOST_THROW_EXCEPTION
0118 # ifndef BOOST_NO_EXCEPTIONS
0119 # define BOOST_THROW_EXCEPTION(x) throw(x)
0120 # else
0121 # define BOOST_THROW_EXCEPTION(x) do{}while(0)
0122 # endif
0123 #endif
0124
0125 #if ! defined(BOOST_JSON_NO_SSE2) && \
0126 ! defined(BOOST_JSON_USE_SSE2)
0127 # if (defined(_M_IX86) && _M_IX86_FP == 2) || \
0128 defined(_M_X64) || defined(__SSE2__)
0129 # define BOOST_JSON_USE_SSE2
0130 # endif
0131 #endif
0132
0133 #ifndef BOOST_SYMBOL_VISIBLE
0134 #define BOOST_SYMBOL_VISIBLE
0135 #endif
0136
0137 #if defined(BOOST_JSON_DOCS)
0138 # define BOOST_JSON_DECL
0139 #else
0140 # if (defined(BOOST_JSON_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_JSON_STATIC_LINK)
0141 # if defined(BOOST_JSON_SOURCE)
0142 # define BOOST_JSON_DECL BOOST_SYMBOL_EXPORT
0143 # else
0144 # define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
0145 # endif
0146 # endif
0147 # ifndef BOOST_JSON_DECL
0148 # define BOOST_JSON_DECL
0149 # endif
0150 # if !defined(BOOST_JSON_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_JSON_NO_LIB)
0151 # define BOOST_LIB_NAME boost_json
0152 # if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_JSON_DYN_LINK)
0153 # define BOOST_DYN_LINK
0154 # endif
0155 # include <boost/config/auto_link.hpp>
0156 # endif
0157 #endif
0158
0159 #ifndef BOOST_JSON_LIKELY
0160 # if defined(__GNUC__) || defined(__clang__)
0161 # define BOOST_JSON_LIKELY(x) __builtin_expect(!!(x), 1)
0162 # else
0163 # define BOOST_JSON_LIKELY(x) x
0164 # endif
0165 #endif
0166
0167 #ifndef BOOST_JSON_UNLIKELY
0168 # if defined(__GNUC__) || defined(__clang__)
0169 # define BOOST_JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
0170 # else
0171 # define BOOST_JSON_UNLIKELY(x) x
0172 # endif
0173 #endif
0174
0175 #ifndef BOOST_JSON_UNREACHABLE
0176 # ifdef _MSC_VER
0177 # define BOOST_JSON_UNREACHABLE() __assume(0)
0178 # elif defined(__GNUC__) || defined(__clang__)
0179 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
0180 # elif defined(__has_builtin)
0181 # if __has_builtin(__builtin_unreachable)
0182 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
0183 # endif
0184 # else
0185 # define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
0186 # endif
0187 #endif
0188
0189 #ifndef BOOST_JSON_ASSUME
0190 # define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
0191 # ifdef _MSC_VER
0192 # undef BOOST_JSON_ASSUME
0193 # define BOOST_JSON_ASSUME(x) __assume(!!(x))
0194 # elif defined(__has_builtin)
0195 # if __has_builtin(__builtin_assume)
0196 # undef BOOST_JSON_ASSUME
0197 # define BOOST_JSON_ASSUME(x) __builtin_assume(!!(x))
0198 # endif
0199 # endif
0200 #endif
0201
0202
0203
0204 #ifndef BOOST_JSON_WEAK_CONSTINIT
0205 # if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1920
0206 # define BOOST_JSON_WEAK_CONSTINIT
0207 # elif defined(__clang__) && __clang_major__ < 4
0208 # define BOOST_JSON_WEAK_CONSTINIT
0209 # endif
0210 #endif
0211
0212
0213
0214 #ifndef BOOST_JSON_MAX_STRING_SIZE
0215 # define BOOST_JSON_NO_MAX_STRING_SIZE
0216 # define BOOST_JSON_MAX_STRING_SIZE 0x7ffffffe
0217 #endif
0218 #ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
0219 # define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
0220 # define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
0221 #endif
0222 #ifndef BOOST_JSON_STACK_BUFFER_SIZE
0223 # define BOOST_JSON_NO_STACK_BUFFER_SIZE
0224 # if defined(__i386__) || defined(__x86_64__) || \
0225 defined(_M_IX86) || defined(_M_X64)
0226 # define BOOST_JSON_STACK_BUFFER_SIZE 4096
0227 # else
0228
0229
0230
0231
0232
0233 # define BOOST_JSON_STACK_BUFFER_SIZE 256
0234 # endif
0235 #endif
0236
0237
0238 #if ! defined(BOOST_JSON_BIG_ENDIAN) && ! defined(BOOST_JSON_LITTLE_ENDIAN)
0239
0240 # if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0241 # define BOOST_JSON_LITTLE_ENDIAN
0242 # elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
0243 # define BOOST_JSON_BIG_ENDIAN
0244 # elif defined(__LITTLE_ENDIAN__)
0245 # define BOOST_JSON_LITTLE_ENDIAN
0246 # elif defined(__BIG_ENDIAN__)
0247 # define BOOST_JSON_BIG_ENDIAN
0248 # elif defined(_MSC_VER) || defined(__i386__) || defined(__x86_64__)
0249 # define BOOST_JSON_LITTLE_ENDIAN
0250 # else
0251 # error The Boost.JSON library could not determine the endianness of this platform. Define either BOOST_JSON_BIG_ENDIAN or BOOST_JSON_LITTLE_ENDIAN.
0252 # endif
0253 #endif
0254
0255 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
0256 # define BOOST_JSON_CONSTINIT constinit
0257 #elif defined(__has_cpp_attribute) && defined(__clang__)
0258 # if __has_cpp_attribute(clang::require_constant_initialization)
0259 # define BOOST_JSON_CONSTINIT [[clang::require_constant_initialization]]
0260 # endif
0261 #elif defined(__GNUC__) && (__GNUC__ >= 10)
0262 # define BOOST_JSON_CONSTINIT __constinit
0263 #endif
0264 #ifndef BOOST_JSON_CONSTINIT
0265 # define BOOST_JSON_CONSTINIT
0266 #endif
0267
0268 namespace boost {
0269 namespace json {
0270 namespace detail {
0271
0272 template<class...>
0273 struct make_void
0274 {
0275 using type =void;
0276 };
0277
0278 template<class... Ts>
0279 using void_t = typename
0280 make_void<Ts...>::type;
0281
0282 template<class T>
0283 using remove_cvref = typename
0284 std::remove_cv<typename
0285 std::remove_reference<T>::type>::type;
0286
0287 template<class T, class U>
0288 T exchange(T& t, U u) noexcept
0289 {
0290 T v = std::move(t);
0291 t = std::move(u);
0292 return v;
0293 }
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306 template<typename T>
0307 struct static_const
0308 {
0309 static constexpr T value {};
0310 };
0311 template<typename T>
0312 constexpr T static_const<T>::value;
0313
0314 #define BOOST_JSON_INLINE_VARIABLE(name, type) \
0315 namespace { constexpr auto& name = \
0316 ::boost::json::detail::static_const<type>::value; \
0317 } struct _unused_ ## name ## _semicolon_bait_
0318
0319 }
0320 }
0321 }
0322
0323 #endif