File indexing completed on 2025-07-02 08:16:02
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/config/pragma_message.hpp>
0015 #include <boost/assert.hpp>
0016 #include <boost/static_assert.hpp>
0017 #include <boost/throw_exception.hpp>
0018 #include <cstdint>
0019 #include <type_traits>
0020 #include <utility>
0021
0022
0023 #if UINTPTR_MAX == UINT64_MAX
0024 # define BOOST_JSON_ARCH 64
0025 #elif UINTPTR_MAX == UINT32_MAX
0026 # define BOOST_JSON_ARCH 32
0027 #else
0028 # error Unknown or unsupported architecture, please open an issue
0029 #endif
0030
0031 #ifndef BOOST_JSON_REQUIRE_CONST_INIT
0032 # define BOOST_JSON_REQUIRE_CONST_INIT
0033 # if __cpp_constinit >= 201907L
0034 # undef BOOST_JSON_REQUIRE_CONST_INIT
0035 # define BOOST_JSON_REQUIRE_CONST_INIT constinit
0036 # elif defined(__clang__) && defined(__has_cpp_attribute)
0037 # if __has_cpp_attribute(clang::require_constant_initialization)
0038 # undef BOOST_JSON_REQUIRE_CONST_INIT
0039 # define BOOST_JSON_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
0040 # endif
0041 # endif
0042 #endif
0043
0044 #ifndef BOOST_JSON_NO_DESTROY
0045 # if defined(__clang__) && defined(__has_cpp_attribute)
0046 # if __has_cpp_attribute(clang::no_destroy)
0047 # define BOOST_JSON_NO_DESTROY [[clang::no_destroy]]
0048 # endif
0049 # endif
0050 #endif
0051
0052 #if ! defined(BOOST_JSON_NO_SSE2) && \
0053 ! defined(BOOST_JSON_USE_SSE2)
0054 # if (defined(_M_IX86) && _M_IX86_FP == 2) || \
0055 defined(_M_X64) || defined(__SSE2__)
0056 # define BOOST_JSON_USE_SSE2
0057 # endif
0058 #endif
0059
0060 #if defined(BOOST_JSON_DOCS)
0061 # define BOOST_JSON_DECL
0062 #else
0063 # if (defined(BOOST_JSON_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)) && !defined(BOOST_JSON_STATIC_LINK)
0064 # if defined(BOOST_JSON_SOURCE)
0065 # define BOOST_JSON_DECL BOOST_SYMBOL_EXPORT
0066 # else
0067 # define BOOST_JSON_DECL BOOST_SYMBOL_IMPORT
0068 # endif
0069 # endif
0070 # ifndef BOOST_JSON_DECL
0071 # define BOOST_JSON_DECL
0072 # endif
0073 # if !defined(BOOST_JSON_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_JSON_NO_LIB)
0074 # define BOOST_LIB_NAME boost_json
0075 # if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_JSON_DYN_LINK)
0076 # define BOOST_DYN_LINK
0077 # endif
0078 # include <boost/config/auto_link.hpp>
0079 # endif
0080 #endif
0081
0082 #ifndef BOOST_JSON_LIKELY
0083 # define BOOST_JSON_LIKELY(x) BOOST_LIKELY( !!(x) )
0084 #endif
0085
0086 #ifndef BOOST_JSON_UNLIKELY
0087 # define BOOST_JSON_UNLIKELY(x) BOOST_UNLIKELY( !!(x) )
0088 #endif
0089
0090 #ifndef BOOST_JSON_UNREACHABLE
0091 # ifdef _MSC_VER
0092 # define BOOST_JSON_UNREACHABLE() __assume(0)
0093 # elif defined(__GNUC__) || defined(__clang__)
0094 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
0095 # elif defined(__has_builtin)
0096 # if __has_builtin(__builtin_unreachable)
0097 # define BOOST_JSON_UNREACHABLE() __builtin_unreachable()
0098 # endif
0099 # else
0100 # define BOOST_JSON_UNREACHABLE() static_cast<void>(0)
0101 # endif
0102 #endif
0103
0104 #ifndef BOOST_JSON_ASSUME
0105 # define BOOST_JSON_ASSUME(x) (!!(x) ? void() : BOOST_JSON_UNREACHABLE())
0106 # ifdef _MSC_VER
0107 # undef BOOST_JSON_ASSUME
0108 # define BOOST_JSON_ASSUME(x) __assume(!!(x))
0109 # elif defined(__has_builtin)
0110 # if __has_builtin(__builtin_assume)
0111 # undef BOOST_JSON_ASSUME
0112 # define BOOST_JSON_ASSUME(x) __builtin_assume(!!(x))
0113 # endif
0114 # endif
0115 #endif
0116
0117
0118
0119 #ifndef BOOST_JSON_WEAK_CONSTINIT
0120 # if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1920
0121 # define BOOST_JSON_WEAK_CONSTINIT
0122 # elif defined(__clang__) && __clang_major__ < 4
0123 # define BOOST_JSON_WEAK_CONSTINIT
0124 # endif
0125 #endif
0126
0127
0128
0129 #ifndef BOOST_JSON_MAX_STRING_SIZE
0130 # define BOOST_JSON_NO_MAX_STRING_SIZE
0131 # define BOOST_JSON_MAX_STRING_SIZE 0x7ffffffe
0132 #endif
0133 #ifndef BOOST_JSON_MAX_STRUCTURED_SIZE
0134 # define BOOST_JSON_NO_MAX_STRUCTURED_SIZE
0135 # define BOOST_JSON_MAX_STRUCTURED_SIZE 0x7ffffffe
0136 #endif
0137 #ifndef BOOST_JSON_STACK_BUFFER_SIZE
0138 # define BOOST_JSON_NO_STACK_BUFFER_SIZE
0139 # if defined(__i386__) || defined(__x86_64__) || \
0140 defined(_M_IX86) || defined(_M_X64)
0141 # define BOOST_JSON_STACK_BUFFER_SIZE 4096
0142 # else
0143
0144
0145
0146
0147
0148 # define BOOST_JSON_STACK_BUFFER_SIZE 256
0149 # endif
0150 #endif
0151
0152 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
0153 # define BOOST_JSON_CONSTINIT constinit
0154 #elif defined(__has_cpp_attribute) && defined(__clang__)
0155 # if __has_cpp_attribute(clang::require_constant_initialization)
0156 # define BOOST_JSON_CONSTINIT [[clang::require_constant_initialization]]
0157 # endif
0158 #elif defined(__GNUC__) && (__GNUC__ >= 10)
0159 # define BOOST_JSON_CONSTINIT __constinit
0160 #endif
0161 #ifndef BOOST_JSON_CONSTINIT
0162 # define BOOST_JSON_CONSTINIT
0163 #endif
0164
0165 namespace boost {
0166 namespace json {
0167 namespace detail {
0168
0169 template<class...>
0170 struct make_void
0171 {
0172 using type =void;
0173 };
0174
0175 template<class... Ts>
0176 using void_t = typename
0177 make_void<Ts...>::type;
0178
0179 template<class T>
0180 using remove_cvref = typename
0181 std::remove_cv<typename
0182 std::remove_reference<T>::type>::type;
0183
0184 template<class T, class U>
0185 T exchange(T& t, U u) noexcept
0186 {
0187 T v = std::move(t);
0188 t = std::move(u);
0189 return v;
0190 }
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203 template<typename T>
0204 struct static_const
0205 {
0206 static constexpr T value {};
0207 };
0208 template<typename T>
0209 constexpr T static_const<T>::value;
0210
0211 #define BOOST_JSON_INLINE_VARIABLE(name, type) \
0212 namespace { constexpr auto& name = \
0213 ::boost::json::detail::static_const<type>::value; \
0214 } struct _unused_ ## name ## _semicolon_bait_
0215
0216 }
0217 }
0218 }
0219
0220 #ifndef BOOST_JSON_ALLOW_DEPRECATED
0221 # ifdef BOOST_ALLOW_DEPRECATED
0222 # define BOOST_JSON_ALLOW_DEPRECATED
0223 # endif
0224 #endif
0225
0226 #if defined(BOOST_GCC) && BOOST_GCC < 50000 && !defined(BOOST_JSON_ALLOW_DEPRECATED)
0227 # 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."
0228 #endif
0229
0230 #ifndef BOOST_JSON_ALLOW_DEPRECATED
0231 # define BOOST_JSON_DEPRECATED(x) BOOST_DEPRECATED(x)
0232 #else
0233 # define BOOST_JSON_DEPRECATED(x)
0234 #endif
0235
0236 #endif