workaround.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP
  11. #define BOOST_CONTAINER_DETAIL_WORKAROUND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)\
  19. && !defined(BOOST_INTERPROCESS_DISABLE_VARIADIC_TMPL)
  20. #define BOOST_CONTAINER_PERFECT_FORWARDING
  21. #endif
  22. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(__GXX_EXPERIMENTAL_CXX0X__)\
  23. && (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__ < 40700)
  24. #define BOOST_CONTAINER_UNIMPLEMENTED_PACK_EXPANSION_TO_FIXED_LIST
  25. #endif
  26. #if defined(BOOST_GCC_VERSION)
  27. # if (BOOST_GCC_VERSION < 40700) || !defined(BOOST_GCC_CXX11)
  28. # define BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS
  29. # endif
  30. #elif defined(BOOST_MSVC)
  31. # if _MSC_FULL_VER < 180020827
  32. # define BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS
  33. # endif
  34. #elif defined(BOOST_CLANG)
  35. # if !__has_feature(cxx_delegating_constructors)
  36. # define BOOST_CONTAINER_NO_CXX11_DELEGATING_CONSTRUCTORS
  37. # endif
  38. #endif
  39. #if defined(BOOST_MSVC) && (_MSC_VER < 1400)
  40. #define BOOST_CONTAINER_TEMPLATED_CONVERSION_OPERATOR_BROKEN
  41. #endif
  42. #if !defined(BOOST_NO_CXX11_HDR_TUPLE) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1700 || BOOST_MSVC == 1600))
  43. #define BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE
  44. #endif
  45. //Macros for documentation purposes. For code, expands to the argument
  46. #define BOOST_CONTAINER_IMPDEF(TYPE) TYPE
  47. #define BOOST_CONTAINER_SEEDOC(TYPE) TYPE
  48. //Macros for memset optimization. In most platforms
  49. //memsetting pointers and floatings is safe and faster.
  50. //
  51. //If your platform does not offer these guarantees
  52. //define these to value zero.
  53. #ifndef BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO
  54. #define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO 1
  55. #endif
  56. #ifndef BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_NULL
  57. #define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL
  58. #endif
  59. #define BOOST_CONTAINER_DOC1ST(TYPE1, TYPE2) TYPE2
  60. #define BOOST_CONTAINER_I ,
  61. #define BOOST_CONTAINER_DOCIGN(T) T
  62. #define BOOST_CONTAINER_DOCONLY(T)
  63. /*
  64. we need to import/export our code only if the user has specifically
  65. asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
  66. libraries to be dynamically linked, or BOOST_CONTAINER_DYN_LINK
  67. if they want just this one to be dynamically liked:
  68. */
  69. #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTAINER_DYN_LINK)
  70. /* export if this is our own source, otherwise import: */
  71. #ifdef BOOST_CONTAINER_SOURCE
  72. # define BOOST_CONTAINER_DECL BOOST_SYMBOL_EXPORT
  73. #else
  74. # define BOOST_CONTAINER_DECL BOOST_SYMBOL_IMPORT
  75. #endif /* BOOST_CONTAINER_SOURCE */
  76. #else
  77. #define BOOST_CONTAINER_DECL
  78. #endif /* DYN_LINK */
  79. //#define BOOST_CONTAINER_DISABLE_FORCEINLINE
  80. #if defined(BOOST_CONTAINER_DISABLE_FORCEINLINE)
  81. #define BOOST_CONTAINER_FORCEINLINE inline
  82. #elif defined(BOOST_CONTAINER_FORCEINLINE_IS_BOOST_FORCELINE)
  83. #define BOOST_CONTAINER_FORCEINLINE BOOST_FORCEINLINE
  84. #elif defined(BOOST_MSVC) && (_MSC_VER <= 1900 || defined(_DEBUG))
  85. //"__forceinline" and MSVC seems to have some bugs in old versions and in debug mode
  86. #define BOOST_CONTAINER_FORCEINLINE inline
  87. #elif defined(BOOST_CLANG) || (defined(BOOST_GCC) && ((__GNUC__ <= 5) || defined(__MINGW32__)))
  88. //Older GCCs and MinGw have problems with forceinline
  89. //Clang can have code bloat issues with forceinline, see
  90. //https://lists.boost.org/boost-users/2023/04/91445.php and
  91. //https://github.com/llvm/llvm-project/issues/62202
  92. #define BOOST_CONTAINER_FORCEINLINE inline
  93. #else
  94. #define BOOST_CONTAINER_FORCEINLINE BOOST_FORCEINLINE
  95. #endif
  96. //#define BOOST_CONTAINER_DISABLE_NOINLINE
  97. #if defined(BOOST_CONTAINER_DISABLE_NOINLINE)
  98. #define BOOST_CONTAINER_NOINLINE
  99. #else
  100. #define BOOST_CONTAINER_NOINLINE BOOST_NOINLINE
  101. #endif
  102. #if !defined(__has_feature)
  103. #define BOOST_CONTAINER_HAS_FEATURE(feature) 0
  104. #else
  105. #define BOOST_CONTAINER_HAS_FEATURE(feature) __has_feature(feature)
  106. #endif
  107. //Detect address sanitizer
  108. #if defined(__SANITIZE_ADDRESS__) || BOOST_CONTAINER_HAS_FEATURE(address_sanitizer)
  109. #define BOOST_CONTAINER_ASAN
  110. #endif
  111. #if (BOOST_CXX_VERSION < 201703L) || !defined(__cpp_deduction_guides)
  112. #define BOOST_CONTAINER_NO_CXX17_CTAD
  113. #endif
  114. #if defined(BOOST_CONTAINER_DISABLE_ATTRIBUTE_NODISCARD)
  115. #define BOOST_CONTAINER_ATTRIBUTE_NODISCARD
  116. #else
  117. #if defined(BOOST_GCC) && ((BOOST_GCC < 100000) || (__cplusplus < 201703L))
  118. //Avoid using it in C++ < 17 and GCC < 10 because it warns in SFINAE contexts
  119. //(see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89070)
  120. #define BOOST_CONTAINER_ATTRIBUTE_NODISCARD
  121. #else
  122. #define BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_ATTRIBUTE_NODISCARD
  123. #endif
  124. #endif
  125. //Configuration options:
  126. //Define this to use std exception types instead of boost::container's own exception types
  127. //#define BOOST_CONTAINER_USE_STD_EXCEPTIONS
  128. namespace boost {
  129. namespace container {
  130. template <typename T1>
  131. BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore(T1 const&)
  132. {}
  133. }} //namespace boost::container {
  134. #if !(defined BOOST_NO_EXCEPTIONS)
  135. # define BOOST_CONTAINER_TRY { try
  136. # define BOOST_CONTAINER_CATCH(x) catch(x)
  137. # define BOOST_CONTAINER_RETHROW throw;
  138. # define BOOST_CONTAINER_CATCH_END }
  139. #else
  140. # if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
  141. # define BOOST_CONTAINER_TRY { if (true)
  142. # define BOOST_CONTAINER_CATCH(x) else if (false)
  143. # else
  144. // warning C4127: conditional expression is constant
  145. # define BOOST_CONTAINER_TRY { \
  146. __pragma(warning(push)) \
  147. __pragma(warning(disable: 4127)) \
  148. if (true) \
  149. __pragma(warning(pop))
  150. # define BOOST_CONTAINER_CATCH(x) else \
  151. __pragma(warning(push)) \
  152. __pragma(warning(disable: 4127)) \
  153. if (false) \
  154. __pragma(warning(pop))
  155. # endif
  156. # define BOOST_CONTAINER_RETHROW
  157. # define BOOST_CONTAINER_CATCH_END }
  158. #endif
  159. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  160. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  161. # define BOOST_CONTAINER_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
  162. # else
  163. # define BOOST_CONTAINER_STATIC_ASSERT( B ) static_assert(B, #B)
  164. # endif
  165. #else
  166. namespace boost {
  167. namespace container {
  168. namespace dtl {
  169. template<bool B>
  170. struct STATIC_ASSERTION_FAILURE;
  171. template<>
  172. struct STATIC_ASSERTION_FAILURE<true> {};
  173. template<unsigned> struct static_assert_test {};
  174. }
  175. }
  176. }
  177. #define BOOST_CONTAINER_STATIC_ASSERT(B) \
  178. typedef ::boost::container::dtl::static_assert_test<\
  179. (unsigned)sizeof(::boost::container::dtl::STATIC_ASSERTION_FAILURE<bool(B)>)>\
  180. BOOST_JOIN(boost_container_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
  181. #endif
  182. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  183. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  184. # define BOOST_CONTAINER_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
  185. # else
  186. # define BOOST_CONTAINER_STATIC_ASSERT_MSG( B, Msg ) static_assert( B, Msg )
  187. # endif
  188. #else
  189. # define BOOST_CONTAINER_STATIC_ASSERT_MSG( B, Msg ) BOOST_CONTAINER_STATIC_ASSERT( B )
  190. #endif
  191. #if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  192. # define BOOST_CONTAINER_CONSTANT_VAR BOOST_INLINE_CONSTEXPR
  193. #else
  194. # define BOOST_CONTAINER_CONSTANT_VAR static BOOST_CONSTEXPR_OR_CONST
  195. #endif
  196. #if defined(__GNUC__) && ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600)
  197. #define BOOST_CONTAINER_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED
  198. #elif defined(__clang__)
  199. #define BOOST_CONTAINER_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED
  200. #endif
  201. #endif //#ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP