config.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*!
  2. @file
  3. Defines configuration macros used throughout the library.
  4. Copyright Louis Dionne 2013-2022
  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. # if _MSC_VER < 1915
  18. # pragma message("Warning: the native Microsoft compiler is not supported due to lack of proper C++14 support.")
  19. # else
  20. // 1. Active issues
  21. // Multiple copy/move ctors
  22. # define BOOST_HANA_WORKAROUND_MSVC_MULTIPLECTOR_106654
  23. // 2. Issues fixed in the development branch of MSVC
  24. // Forward declaration of class template member function returning decltype(auto)
  25. # define BOOST_HANA_WORKAROUND_MSVC_DECLTYPEAUTO_RETURNTYPE_662735
  26. // 3. Issues fixed conditionally
  27. // Requires __declspec(empty_bases)
  28. // Empty base optimization
  29. # define BOOST_HANA_WORKAROUND_MSVC_EMPTYBASE
  30. // Requires /experimental:preprocessor
  31. // Variadic macro expansion
  32. # if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
  33. # define BOOST_HANA_WORKAROUND_MSVC_PREPROCESSOR_616033
  34. # endif
  35. # endif
  36. #elif defined(__clang__) && defined(_MSC_VER) // Clang-cl (Clang for Windows)
  37. # define BOOST_HANA_CONFIG_CLANG_CL
  38. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
  39. __clang_major__, __clang_minor__, __clang_patchlevel__)
  40. #elif defined(__clang__) && defined(__apple_build_version__) // Apple's Clang
  41. # define BOOST_HANA_CONFIG_APPLE_CLANG
  42. # if __apple_build_version__ >= 6020049
  43. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION(3, 6, 0)
  44. # endif
  45. #elif defined(__clang__) // genuine Clang
  46. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
  47. __clang_major__, __clang_minor__, __clang_patchlevel__)
  48. #elif defined(__GNUC__) // GCC
  49. # define BOOST_HANA_CONFIG_GCC BOOST_HANA_CONFIG_VERSION( \
  50. __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
  51. #endif
  52. //////////////////////////////////////////////////////////////////////////////
  53. // Check the compiler for general C++14 capabilities
  54. //////////////////////////////////////////////////////////////////////////////
  55. #if (__cplusplus < 201400)
  56. # if defined(_MSC_VER)
  57. # if _MSC_VER < 1915
  58. # 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'.")
  59. # endif
  60. # else
  61. # warning "Your compiler doesn't provide C++14 or higher capabilities. Try adding the compiler flag '-std=c++14' or '-std=c++1y'."
  62. # endif
  63. #endif
  64. //////////////////////////////////////////////////////////////////////////////
  65. // Caveats and other compiler-dependent options
  66. //////////////////////////////////////////////////////////////////////////////
  67. // `BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA` enables some constructs requiring
  68. // `constexpr` lambdas, which are in the language starting with C++17.
  69. //
  70. // Always disabled for now because Clang only has partial support for them
  71. // (captureless lambdas only).
  72. #if defined(__cplusplus) && __cplusplus > 201402L
  73. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA constexpr
  74. // # define BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA
  75. #else
  76. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA /* nothing */
  77. #endif
  78. // `BOOST_HANA_CONSTEXPR_LAMBDA` expands to `constexpr` if constexpr lambdas
  79. // are supported and to nothing otherwise.
  80. #if defined(BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA)
  81. # define BOOST_HANA_CONSTEXPR_LAMBDA constexpr
  82. #else
  83. # define BOOST_HANA_CONSTEXPR_LAMBDA /* nothing */
  84. #endif
  85. // `BOOST_HANA_INLINE_VARIABLE` expands to `inline` when C++17 inline variables
  86. // are supported, and to nothing otherwise. This allows marking global variables
  87. // defined in a header as `inline` to avoid potential ODR violations.
  88. #if defined(__cplusplus) && __cplusplus > 201402L
  89. # define BOOST_HANA_INLINE_VARIABLE inline
  90. #else
  91. # define BOOST_HANA_INLINE_VARIABLE /* nothing */
  92. #endif
  93. //////////////////////////////////////////////////////////////////////////////
  94. // Library features and options that can be tweaked by users
  95. //////////////////////////////////////////////////////////////////////////////
  96. #if defined(BOOST_HANA_DOXYGEN_INVOKED) || \
  97. (defined(NDEBUG) && !defined(BOOST_HANA_CONFIG_DISABLE_ASSERTIONS))
  98. //! @ingroup group-config
  99. //! Disables the `BOOST_HANA_*_ASSERT` macro & friends.
  100. //!
  101. //! When this macro is defined, the `BOOST_HANA_*_ASSERT` macro & friends
  102. //! are disabled, i.e. they expand to nothing.
  103. //!
  104. //! This macro is defined automatically when `NDEBUG` is defined. It can
  105. //! also be defined by users before including this header or defined on
  106. //! the command line.
  107. # define BOOST_HANA_CONFIG_DISABLE_ASSERTIONS
  108. #endif
  109. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  110. //! @ingroup group-config
  111. //! Disables concept checks in interface methods.
  112. //!
  113. //! When this macro is not defined (the default), tag-dispatched methods
  114. //! will make sure the arguments they are passed are models of the proper
  115. //! concept(s). This can be very helpful in catching programming errors,
  116. //! but it is also slightly less compile-time efficient. You should
  117. //! probably always leave the checks enabled (and hence never define this
  118. //! macro), except perhaps in translation units that are compiled very
  119. //! often but whose code using Hana is modified very rarely.
  120. # define BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  121. #endif
  122. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  123. //! @ingroup group-config
  124. //! Enables usage of the "string literal operator template" GNU extension.
  125. //!
  126. //! That operator is not part of the language yet, but it is supported by
  127. //! both Clang and GCC. This operator allows Hana to provide the nice `_s`
  128. //! user-defined literal for creating compile-time strings.
  129. //!
  130. //! When this macro is not defined, the GNU extension will be not used
  131. //! by Hana. Because this is a non-standard extension, the macro is not
  132. //! defined by default.
  133. # define BOOST_HANA_CONFIG_ENABLE_STRING_UDL
  134. #endif
  135. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  136. //! @ingroup group-config
  137. //! Enables additional assertions and sanity checks to be done by Hana.
  138. //!
  139. //! When this macro is defined (it is __not defined__ by default),
  140. //! additional sanity checks may be done by Hana. These checks may
  141. //! be costly to perform, either in terms of compilation time or in
  142. //! terms of execution time. These checks may help debugging an
  143. //! application during its initial development, but they should not
  144. //! be enabled as part of the normal configuration.
  145. # define BOOST_HANA_CONFIG_ENABLE_DEBUG_MODE
  146. #endif
  147. #endif // !BOOST_HANA_CONFIG_HPP