config.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. # 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 BOOST_HANA_CONFIG_VERSION( \
  38. __clang_major__, __clang_minor__, __clang_patchlevel__)
  39. #elif defined(__clang__) && defined(__apple_build_version__) // Apple's Clang
  40. # if __apple_build_version__ >= 6020049
  41. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION(3, 6, 0)
  42. # endif
  43. #elif defined(__clang__) // genuine Clang
  44. # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
  45. __clang_major__, __clang_minor__, __clang_patchlevel__)
  46. #elif defined(__GNUC__) // GCC
  47. # define BOOST_HANA_CONFIG_GCC BOOST_HANA_CONFIG_VERSION( \
  48. __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
  49. #endif
  50. //////////////////////////////////////////////////////////////////////////////
  51. // Check the compiler for general C++14 capabilities
  52. //////////////////////////////////////////////////////////////////////////////
  53. #if (__cplusplus < 201400)
  54. # if defined(_MSC_VER)
  55. # if _MSC_VER < 1915
  56. # 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'.")
  57. # endif
  58. # else
  59. # warning "Your compiler doesn't provide C++14 or higher capabilities. Try adding the compiler flag '-std=c++14' or '-std=c++1y'."
  60. # endif
  61. #endif
  62. //////////////////////////////////////////////////////////////////////////////
  63. // Caveats and other compiler-dependent options
  64. //////////////////////////////////////////////////////////////////////////////
  65. // `BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA` enables some constructs requiring
  66. // `constexpr` lambdas, which are in the language starting with C++17.
  67. //
  68. // Always disabled for now because Clang only has partial support for them
  69. // (captureless lambdas only).
  70. #if defined(__cplusplus) && __cplusplus > 201402L
  71. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA constexpr
  72. // # define BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA
  73. #else
  74. # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA /* nothing */
  75. #endif
  76. // `BOOST_HANA_CONSTEXPR_LAMBDA` expands to `constexpr` if constexpr lambdas
  77. // are supported and to nothing otherwise.
  78. #if defined(BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA)
  79. # define BOOST_HANA_CONSTEXPR_LAMBDA constexpr
  80. #else
  81. # define BOOST_HANA_CONSTEXPR_LAMBDA /* nothing */
  82. #endif
  83. //////////////////////////////////////////////////////////////////////////////
  84. // Namespace macros
  85. //////////////////////////////////////////////////////////////////////////////
  86. #define BOOST_HANA_NAMESPACE_BEGIN namespace boost { namespace hana {
  87. #define BOOST_HANA_NAMESPACE_END }}
  88. //////////////////////////////////////////////////////////////////////////////
  89. // Library features and options that can be tweaked by users
  90. //////////////////////////////////////////////////////////////////////////////
  91. #if defined(BOOST_HANA_DOXYGEN_INVOKED) || \
  92. (defined(NDEBUG) && !defined(BOOST_HANA_CONFIG_DISABLE_ASSERTIONS))
  93. //! @ingroup group-config
  94. //! Disables the `BOOST_HANA_*_ASSERT` macro & friends.
  95. //!
  96. //! When this macro is defined, the `BOOST_HANA_*_ASSERT` macro & friends
  97. //! are disabled, i.e. they expand to nothing.
  98. //!
  99. //! This macro is defined automatically when `NDEBUG` is defined. It can
  100. //! also be defined by users before including this header or defined on
  101. //! the command line.
  102. # define BOOST_HANA_CONFIG_DISABLE_ASSERTIONS
  103. #endif
  104. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  105. //! @ingroup group-config
  106. //! Disables concept checks in interface methods.
  107. //!
  108. //! When this macro is not defined (the default), tag-dispatched methods
  109. //! will make sure the arguments they are passed are models of the proper
  110. //! concept(s). This can be very helpful in catching programming errors,
  111. //! but it is also slightly less compile-time efficient. You should
  112. //! probably always leave the checks enabled (and hence never define this
  113. //! macro), except perhaps in translation units that are compiled very
  114. //! often but whose code using Hana is modified very rarely.
  115. # define BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  116. #endif
  117. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  118. //! @ingroup group-config
  119. //! Enables usage of the "string literal operator template" GNU extension.
  120. //!
  121. //! That operator is not part of the language yet, but it is supported by
  122. //! both Clang and GCC. This operator allows Hana to provide the nice `_s`
  123. //! user-defined literal for creating compile-time strings.
  124. //!
  125. //! When this macro is not defined, the GNU extension will be not used
  126. //! by Hana. Because this is a non-standard extension, the macro is not
  127. //! defined by default.
  128. # define BOOST_HANA_CONFIG_ENABLE_STRING_UDL
  129. #endif
  130. #if defined(BOOST_HANA_DOXYGEN_INVOKED)
  131. //! @ingroup group-config
  132. //! Enables additional assertions and sanity checks to be done by Hana.
  133. //!
  134. //! When this macro is defined (it is __not defined__ by default),
  135. //! additional sanity checks may be done by Hana. These checks may
  136. //! be costly to perform, either in terms of compilation time or in
  137. //! terms of execution time. These checks may help debugging an
  138. //! application during its initial development, but they should not
  139. //! be enabled as part of the normal configuration.
  140. # define BOOST_HANA_CONFIG_ENABLE_DEBUG_MODE
  141. #endif
  142. #endif // !BOOST_HANA_CONFIG_HPP