config.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. // Copyright (c) 2019-2020 Krystian Stasiowski (sdkrystian at gmail dot com)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Official repository: https://github.com/boostorg/static_string
  9. //
  10. #ifndef BOOST_STATIC_STRING_CONFIG_HPP
  11. #define BOOST_STATIC_STRING_CONFIG_HPP
  12. // Are we dependent on Boost?
  13. // #define BOOST_STATIC_STRING_STANDALONE
  14. // Can we have deduction guides?
  15. #if __cpp_deduction_guides >= 201703L
  16. #define BOOST_STATIC_STRING_USE_DEDUCT
  17. #endif
  18. // Include <version> if we can
  19. #ifdef __has_include
  20. #if __has_include(<version>)
  21. #include <version>
  22. #endif
  23. #endif
  24. // Can we use __has_builtin?
  25. #ifdef __has_builtin
  26. #define BOOST_STATIC_STRING_HAS_BUILTIN(arg) __has_builtin(arg)
  27. #else
  28. #define BOOST_STATIC_STRING_HAS_BUILTIN(arg) 0
  29. #endif
  30. // Can we use is_constant_evaluated?
  31. #if __cpp_lib_is_constant_evaluated >= 201811L
  32. #define BOOST_STATIC_STRING_IS_CONST_EVAL std::is_constant_evaluated()
  33. #elif BOOST_STATIC_STRING_HAS_BUILTIN(__builtin_is_constant_evaluated)
  34. #define BOOST_STATIC_STRING_IS_CONST_EVAL __builtin_is_constant_evaluated()
  35. #endif
  36. // Check for an attribute
  37. #if defined(__has_cpp_attribute)
  38. #define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) __has_cpp_attribute(x)
  39. #elif defined(__has_attribute)
  40. #define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) __has_attribute(x)
  41. #else
  42. #define BOOST_STATIC_STRING_CHECK_FOR_ATTR(x) 0
  43. #endif
  44. // Decide which attributes we can use
  45. #define BOOST_STATIC_STRING_UNLIKELY
  46. #define BOOST_STATIC_STRING_NODISCARD
  47. #define BOOST_STATIC_STRING_NORETURN
  48. #define BOOST_STATIC_STRING_NO_NORETURN
  49. // unlikely
  50. #if BOOST_STATIC_STRING_CHECK_FOR_ATTR(unlikely)
  51. #undef BOOST_STATIC_STRING_UNLIKELY
  52. #define BOOST_STATIC_STRING_UNLIKELY [[unlikely]]
  53. #endif
  54. // nodiscard
  55. #if BOOST_STATIC_STRING_CHECK_FOR_ATTR(nodiscard)
  56. #undef BOOST_STATIC_STRING_NODISCARD
  57. #define BOOST_STATIC_STRING_NODISCARD [[nodiscard]]
  58. #elif defined(_MSC_VER) && _MSC_VER >= 1700
  59. #undef BOOST_STATIC_STRING_NODISCARD
  60. #define BOOST_STATIC_STRING_NODISCARD _Check_return_
  61. #elif defined(__GNUC__) || defined(__clang__)
  62. #undef BOOST_STATIC_STRING_NODISCARD
  63. #define BOOST_STATIC_STRING_NODISCARD __attribute__((warn_unused_result))
  64. #endif
  65. // noreturn
  66. #if BOOST_STATIC_STRING_CHECK_FOR_ATTR(noreturn)
  67. #undef BOOST_STATIC_STRING_NORETURN
  68. #undef BOOST_STATIC_STRING_NO_NORETURN
  69. #define BOOST_STATIC_STRING_NORETURN [[noreturn]]
  70. #elif defined(_MSC_VER)
  71. #undef BOOST_STATIC_STRING_NORETURN
  72. #undef BOOST_STATIC_STRING_NO_NORETURN
  73. #define BOOST_STATIC_STRING_NORETURN __declspec(noreturn)
  74. #elif defined(__GNUC__) || defined(__clang__)
  75. #undef BOOST_STATIC_STRING_NORETURN
  76. #undef BOOST_STATIC_STRING_NO_NORETURN
  77. #define BOOST_STATIC_STRING_NORETURN __attribute__((__noreturn__))
  78. #endif
  79. // _MSVC_LANG isn't avaliable until after VS2015
  80. #if defined(_MSC_VER) && _MSC_VER < 1910L
  81. // The constexpr support in this version is effectively that of
  82. // c++11, so we treat it as such
  83. #define BOOST_STATIC_STRING_STANDARD_VERSION 201103L
  84. #elif defined(_MSVC_LANG)
  85. // MSVC doesn't define __cplusplus by default
  86. #define BOOST_STATIC_STRING_STANDARD_VERSION _MSVC_LANG
  87. #else
  88. #define BOOST_STATIC_STRING_STANDARD_VERSION __cplusplus
  89. #endif
  90. // Decide what level of constexpr we can use
  91. #define BOOST_STATIC_STRING_CPP20_CONSTEXPR
  92. #define BOOST_STATIC_STRING_CPP17_CONSTEXPR
  93. #define BOOST_STATIC_STRING_CPP14_CONSTEXPR
  94. #define BOOST_STATIC_STRING_CPP11_CONSTEXPR
  95. #if BOOST_STATIC_STRING_STANDARD_VERSION >= 202002L
  96. #define BOOST_STATIC_STRING_CPP20
  97. #undef BOOST_STATIC_STRING_CPP20_CONSTEXPR
  98. #define BOOST_STATIC_STRING_CPP20_CONSTEXPR constexpr
  99. #endif
  100. #if BOOST_STATIC_STRING_STANDARD_VERSION >= 201703L
  101. #define BOOST_STATIC_STRING_CPP17
  102. #undef BOOST_STATIC_STRING_CPP17_CONSTEXPR
  103. #define BOOST_STATIC_STRING_CPP17_CONSTEXPR constexpr
  104. #endif
  105. #if BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L
  106. #define BOOST_STATIC_STRING_CPP14
  107. #undef BOOST_STATIC_STRING_CPP14_CONSTEXPR
  108. #define BOOST_STATIC_STRING_CPP14_CONSTEXPR constexpr
  109. #endif
  110. #if BOOST_STATIC_STRING_STANDARD_VERSION >= 201103L
  111. #define BOOST_STATIC_STRING_CPP11
  112. #undef BOOST_STATIC_STRING_CPP11_CONSTEXPR
  113. #define BOOST_STATIC_STRING_CPP11_CONSTEXPR constexpr
  114. #endif
  115. // Boost and non-Boost versions of utilities
  116. #ifndef BOOST_STATIC_STRING_STANDALONE
  117. #ifndef BOOST_STATIC_STRING_THROW
  118. #define BOOST_STATIC_STRING_THROW(ex) BOOST_THROW_EXCEPTION(ex)
  119. #endif
  120. #ifndef BOOST_STATIC_STRING_STATIC_ASSERT
  121. #define BOOST_STATIC_STRING_STATIC_ASSERT(cond, msg) BOOST_STATIC_ASSERT_MSG(cond, msg)
  122. #endif
  123. #ifndef BOOST_STATIC_STRING_ASSERT
  124. #define BOOST_STATIC_STRING_ASSERT(cond) BOOST_ASSERT(cond)
  125. #endif
  126. #else
  127. #ifndef BOOST_STATIC_STRING_THROW
  128. #define BOOST_STATIC_STRING_THROW(ex) throw ex
  129. #endif
  130. #ifndef BOOST_STATIC_STRING_STATIC_ASSERT
  131. #define BOOST_STATIC_STRING_STATIC_ASSERT(cond, msg) static_assert(cond, msg)
  132. #endif
  133. #ifndef BOOST_STATIC_STRING_ASSERT
  134. #define BOOST_STATIC_STRING_ASSERT(cond) assert(cond)
  135. #endif
  136. #endif
  137. #ifndef BOOST_STATIC_STRING_STANDALONE
  138. #include <boost/assert.hpp>
  139. #include <boost/container_hash/hash.hpp>
  140. #include <boost/static_assert.hpp>
  141. #include <boost/utility/string_view.hpp>
  142. #include <boost/throw_exception.hpp>
  143. #else
  144. #include <cassert>
  145. #include <stdexcept>
  146. #include <string_view>
  147. #endif
  148. // Compiler bug prevents constexpr from working with clang 4.x and 5.x
  149. // if it is detected, we disable constexpr.
  150. #if (BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L && \
  151. BOOST_STATIC_STRING_STANDARD_VERSION < 201703L) && \
  152. defined(__clang__) && \
  153. ((__clang_major__ == 4) || (__clang_major__ == 5))
  154. // This directive works on clang
  155. #warning "C++14 constexpr is not supported in clang 4.x and 5.x due to a compiler bug."
  156. #ifdef BOOST_STATIC_STRING_CPP14
  157. #undef BOOST_STATIC_STRING_CPP14
  158. #endif
  159. #undef BOOST_STATIC_STRING_CPP14_CONSTEXPR
  160. #define BOOST_STATIC_STRING_CPP14_CONSTEXPR
  161. #endif
  162. // This is for compiler/library configurations
  163. // that cannot use the library comparison function
  164. // objects at all in constant expresssions. In these
  165. // cases, we use whatever will make more constexpr work.
  166. #if defined(__clang__) && \
  167. (defined(__GLIBCXX__) || defined(_MSC_VER))
  168. #define BOOST_STATIC_STRING_NO_PTR_COMP_FUNCTIONS
  169. #endif
  170. // In gcc-5, we cannot use throw expressions in a
  171. // constexpr function. However, we have a workaround
  172. // for this using constructors. Also, non-static member
  173. // functions that return the class they are a member of
  174. // causes an ICE during constant evaluation.
  175. #if defined(__GNUC__) && (__GNUC__== 5) && \
  176. defined(BOOST_STATIC_STRING_CPP14)
  177. #define BOOST_STATIC_STRING_GCC5_BAD_CONSTEXPR
  178. #endif
  179. namespace boost {
  180. namespace static_strings {
  181. /// The type of `basic_string_view` used by the library
  182. template<typename CharT, typename Traits>
  183. using basic_string_view =
  184. #ifndef BOOST_STATIC_STRING_STANDALONE
  185. boost::basic_string_view<CharT, Traits>;
  186. #else
  187. std::basic_string_view<CharT, Traits>;
  188. #endif
  189. } // static_strings
  190. } // boost
  191. #endif