config.hpp 6.6 KB

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