config.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*!
  2. @file
  3. Defines configuration macros used throughout the library.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_CONFIG_HPP
  9. #define BOOST_HANA_CONFIG_HPP
  10. #include <boost/hana/version.hpp>
  11. //////////////////////////////////////////////////////////////////////////////
  12. // Detect the compiler
  13. //////////////////////////////////////////////////////////////////////////////
  14. #if defined(_MSC_VER) && !defined(__clang__) // MSVC
  15. // This must be checked first, because otherwise it produces a fatal
  16. // error due to unrecognized #warning directives used below.
  17. # pragma message("Warning: the native Microsoft compiler is not supported due to lack of proper C++14 support.")
  18. #elif defined(__clang__) && defined(_MSC_VER) // Clang-cl (Clang for Windows)
  19. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
  20. __clang_major__, __clang_minor__, __clang_patchlevel__)
  21. # if BOOST_HANA_CONFIG_CLANG < BOOST_HANA_CONFIG_VERSION(3, 5, 0)
  22. # warning "Versions of Clang prior to 3.5.0 are not supported by Hana."
  23. # endif
  24. # if _MSC_VER < 1900
  25. # warning "Clang-cl is only supported with the -fms-compatibility-version parameter set to 19 and above."
  26. # endif
  27. #elif defined(__clang__) && defined(__apple_build_version__) // Apple's Clang
  28. # if __apple_build_version__ >= 6020049
  29. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION(3, 6, 0)
  30. # else
  31. # warning "Versions of Apple's Clang prior to the one shipped with Xcode 6.3 are not supported by Hana."
  32. # endif
  33. #elif defined(__clang__) // genuine Clang
  34. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
  35. __clang_major__, __clang_minor__, __clang_patchlevel__)
  36. # if BOOST_HANA_CONFIG_CLANG < BOOST_HANA_CONFIG_VERSION(3, 5, 0)
  37. # warning "Versions of Clang prior to 3.5.0 are not supported by Hana."
  38. # endif
  39. #elif defined(__GNUC__) // GCC
  40. # define BOOST_HANA_CONFIG_GCC BOOST_HANA_CONFIG_VERSION( \
  41. __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
  42. # if BOOST_HANA_CONFIG_GCC < BOOST_HANA_CONFIG_VERSION(6, 0, 0)
  43. # warning "Versions of GCC prior to 6.0.0 are not supported by Hana."
  44. # endif
  45. #else
  46. # warning "Your compiler is not officially supported by Hana or it was not detected properly."
  47. #endif
  48. //////////////////////////////////////////////////////////////////////////////
  49. // Check the compiler for general C++14 capabilities
  50. //////////////////////////////////////////////////////////////////////////////
  51. #if (__cplusplus < 201400)
  52. # if defined(_MSC_VER)
  53. # pragma message("Warning: Your compiler doesn't provide C++14 or higher capabilities. Try adding the compiler flag '-std=c++14' or '-std=c++1y'.")
  54. # else
  55. # warning "Your compiler doesn't provide C++14 or higher capabilities. Try adding the compiler flag '-std=c++14' or '-std=c++1y'."
  56. # endif
  57. #endif
  58. //////////////////////////////////////////////////////////////////////////////
  59. // Detect the standard library
  60. //////////////////////////////////////////////////////////////////////////////
  61. // We include this header, which normally defines the proper detection macros.
  62. // At least, libc++ and libstdc++ do.
  63. #include <cstddef>
  64. #if defined(_LIBCPP_VERSION)
  65. # define BOOST_HANA_CONFIG_LIBCPP BOOST_HANA_CONFIG_VERSION( \
  66. ((_LIBCPP_VERSION) / 1000) % 10, 0, (_LIBCPP_VERSION) % 1000)
  67. # if BOOST_HANA_CONFIG_LIBCPP < BOOST_HANA_CONFIG_VERSION(1, 0, 101)
  68. # warning "Versions of libc++ prior to the one shipped with Clang 3.5.0 are not supported by Hana."
  69. # endif
  70. #elif defined(__GLIBCXX__)
  71. // We do not define a macro to keep track of libstdc++'s version, because
  72. // we have no scalable way of associating a value of __GLIBCXX__ to the
  73. // corresponding GCC release. Instead, we just check that the release date
  74. // of the libstdc++ in use is recent enough, which should indicate that it
  75. // was released with a GCC >= 5.1, which in turn indicates good enough C++14
  76. // support.
  77. # if __GLIBCXX__ < 20150422 // --> the libstdc++ shipped with GCC 5.1.0
  78. # warning "Versions of libstdc++ prior to the one shipped with GCC 5.1.0 are not supported by Hana for lack of full C++14 support."
  79. # endif
  80. # define BOOST_HANA_CONFIG_LIBSTDCXX
  81. #elif defined(_MSC_VER)
  82. # define BOOST_HANA_CONFIG_LIBMSVCCXX
  83. #else
  84. # warning "Your standard library is not officially supported by Hana or it was not detected properly."
  85. #endif
  86. //////////////////////////////////////////////////////////////////////////////
  87. // Caveats and other compiler-dependent options
  88. //////////////////////////////////////////////////////////////////////////////
  89. // `BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA` enables some constructs requiring
  90. // `constexpr` lambdas, which are in the language starting with C++17.
  91. //
  92. // Always disabled for now because Clang only has partial support for them
  93. // (captureless lambdas only).
  94. #if defined(__cplusplus) && __cplusplus > 201402L
  95. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA constexpr
  96. // # define BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA
  97. #else
  98. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA /* nothing */
  99. #endif
  100. // `BOOST_HANA_CONSTEXPR_LAMBDA` expands to `constexpr` if constexpr lambdas
  101. // are supported and to nothing otherwise.
  102. #if defined(BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA)
  103. # define BOOST_HANA_CONSTEXPR_LAMBDA constexpr
  104. #else
  105. # define BOOST_HANA_CONSTEXPR_LAMBDA /* nothing */
  106. #endif
  107. // There's a bug in std::tuple_cat in libc++ right now.
  108. // See http://llvm.org/bugs/show_bug.cgi?id=22806.
  109. #if defined(BOOST_HANA_CONFIG_LIBCPP)
  110. # define BOOST_HANA_CONFIG_LIBCPP_HAS_BUG_22806
  111. #endif
  112. //////////////////////////////////////////////////////////////////////////////
  113. // Namespace macros
  114. //////////////////////////////////////////////////////////////////////////////
  115. #define BOOST_HANA_NAMESPACE_BEGIN namespace boost { namespace hana {
  116. #define BOOST_HANA_NAMESPACE_END }}
  117. //////////////////////////////////////////////////////////////////////////////
  118. // Library features and options that can be tweaked by users
  119. //////////////////////////////////////////////////////////////////////////////
  120. #if defined(BOOST_HANA_DOXYGEN_INVOKED) || \
  121. (defined(NDEBUG) && !defined(BOOST_HANA_CONFIG_DISABLE_ASSERTIONS))
  122. //! @ingroup group-config
  123. //! Disables the `BOOST_HANA_*_ASSERT` macro & friends.
  124. //!
  125. //! When this macro is defined, the `BOOST_HANA_*_ASSERT` macro & friends
  126. //! are disabled, i.e. they expand to nothing.
  127. //!
  128. //! This macro is defined automatically when `NDEBUG` is defined. It can
  129. //! also be defined by users before including this header or defined on
  130. //! the command line.
  131. # define BOOST_HANA_CONFIG_DISABLE_ASSERTIONS
  132. #endif
  133. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  134. //! @ingroup group-config
  135. //! Disables concept checks in interface methods.
  136. //!
  137. //! When this macro is not defined (the default), tag-dispatched methods
  138. //! will make sure the arguments they are passed are models of the proper
  139. //! concept(s). This can be very helpful in catching programming errors,
  140. //! but it is also slightly less compile-time efficient. You should
  141. //! probably always leave the checks enabled (and hence never define this
  142. //! macro), except perhaps in translation units that are compiled very
  143. //! often but whose code using Hana is modified very rarely.
  144. # define BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  145. #endif
  146. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  147. //! @ingroup group-config
  148. //! Enables usage of the "string literal operator template" GNU extension.
  149. //!
  150. //! That operator is not part of the language yet, but it is supported by
  151. //! both Clang and GCC. This operator allows Hana to provide the nice `_s`
  152. //! user-defined literal for creating compile-time strings.
  153. //!
  154. //! When this macro is not defined, the GNU extension will be not used
  155. //! by Hana. Because this is a non-standard extension, the macro is not
  156. //! defined by default.
  157. # define BOOST_HANA_CONFIG_ENABLE_STRING_UDL
  158. #endif
  159. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  160. //! @ingroup group-config
  161. //! Enables additional assertions and sanity checks to be done by Hana.
  162. //!
  163. //! When this macro is defined (it is __not defined__ by default),
  164. //! additional sanity checks may be done by Hana. These checks may
  165. //! be costly to perform, either in terms of compilation time or in
  166. //! terms of execution time. These checks may help debugging an
  167. //! application during its initial development, but they should not
  168. //! be enabled as part of the normal configuration.
  169. # define BOOST_HANA_CONFIG_ENABLE_DEBUG_MODE
  170. #endif
  171. #endif // !BOOST_HANA_CONFIG_HPP