3 Defines configuration macros used throughout the library.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_CONFIG_HPP
11 #define BOOST_HANA_CONFIG_HPP
13 #include <boost/hana/version.hpp>
16 //////////////////////////////////////////////////////////////////////////////
17 // Detect the compiler
18 //////////////////////////////////////////////////////////////////////////////
20 #if defined(_MSC_VER) && !defined(__clang__) // MSVC
21 // This must be checked first, because otherwise it produces a fatal
22 // error due to unrecognized #warning directives used below.
25 # pragma message("Warning: the native Microsoft compiler is not supported due to lack of proper C++14 support.")
28 // Multiple copy/move ctors
29 # define BOOST_HANA_WORKAROUND_MSVC_MULTIPLECTOR_106654
31 // 2. Issues fixed in the development branch of MSVC
32 // Forward declaration of class template member function returning decltype(auto)
33 # define BOOST_HANA_WORKAROUND_MSVC_DECLTYPEAUTO_RETURNTYPE_662735
35 // 3. Issues fixed conditionally
36 // Requires __declspec(empty_bases)
37 // Empty base optimization
38 # define BOOST_HANA_WORKAROUND_MSVC_EMPTYBASE
40 // Requires /experimental:preprocessor
41 // Variadic macro expansion
42 # if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL
43 # define BOOST_HANA_WORKAROUND_MSVC_PREPROCESSOR_616033
47 #elif defined(__clang__) && defined(_MSC_VER) // Clang-cl (Clang for Windows)
49 # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
50 __clang_major__, __clang_minor__, __clang_patchlevel__)
52 #elif defined(__clang__) && defined(__apple_build_version__) // Apple's Clang
54 # if __apple_build_version__ >= 6020049
55 # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION(3, 6, 0)
58 #elif defined(__clang__) // genuine Clang
60 # define BOOST_HANA_CONFIG_CLANG BOOST_HANA_CONFIG_VERSION( \
61 __clang_major__, __clang_minor__, __clang_patchlevel__)
63 #elif defined(__GNUC__) // GCC
65 # define BOOST_HANA_CONFIG_GCC BOOST_HANA_CONFIG_VERSION( \
66 __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
70 //////////////////////////////////////////////////////////////////////////////
71 // Check the compiler for general C++14 capabilities
72 //////////////////////////////////////////////////////////////////////////////
73 #if (__cplusplus < 201400)
74 # if defined(_MSC_VER)
76 # 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'.")
79 # warning "Your compiler doesn't provide C++14 or higher capabilities. Try adding the compiler flag '-std=c++14' or '-std=c++1y'."
83 //////////////////////////////////////////////////////////////////////////////
84 // Caveats and other compiler-dependent options
85 //////////////////////////////////////////////////////////////////////////////
87 // `BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA` enables some constructs requiring
88 // `constexpr` lambdas, which are in the language starting with C++17.
90 // Always disabled for now because Clang only has partial support for them
91 // (captureless lambdas only).
92 #if defined(__cplusplus) && __cplusplus > 201402L
93 # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA constexpr
94 // # define BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA
96 # define BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA /* nothing */
99 // `BOOST_HANA_CONSTEXPR_LAMBDA` expands to `constexpr` if constexpr lambdas
100 // are supported and to nothing otherwise.
101 #if defined(BOOST_HANA_CONFIG_HAS_CONSTEXPR_LAMBDA)
102 # define BOOST_HANA_CONSTEXPR_LAMBDA constexpr
104 # define BOOST_HANA_CONSTEXPR_LAMBDA /* nothing */
107 // `BOOST_HANA_INLINE_VARIABLE` expands to `inline` when C++17 inline variables
108 // are supported, and to nothing otherwise. This allows marking global variables
109 // defined in a header as `inline` to avoid potential ODR violations.
110 #if defined(__cplusplus) && __cplusplus > 201402L
111 # define BOOST_HANA_INLINE_VARIABLE inline
113 # define BOOST_HANA_INLINE_VARIABLE /* nothing */
116 //////////////////////////////////////////////////////////////////////////////
117 // Library features and options that can be tweaked by users
118 //////////////////////////////////////////////////////////////////////////////
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.
125 //! When this macro is defined, the `BOOST_HANA_*_ASSERT` macro & friends
126 //! are disabled, i.e. they expand to nothing.
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
134 #if defined(BOOST_HANA_DOXYGEN_INVOKED)
135 //! @ingroup group-config
136 //! Disables concept checks in interface methods.
138 //! When this macro is not defined (the default), tag-dispatched methods
139 //! will make sure the arguments they are passed are models of the proper
140 //! concept(s). This can be very helpful in catching programming errors,
141 //! but it is also slightly less compile-time efficient. You should
142 //! probably always leave the checks enabled (and hence never define this
143 //! macro), except perhaps in translation units that are compiled very
144 //! often but whose code using Hana is modified very rarely.
145 # define BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
148 #if defined(BOOST_HANA_DOXYGEN_INVOKED)
149 //! @ingroup group-config
150 //! Enables usage of the "string literal operator template" GNU extension.
152 //! That operator is not part of the language yet, but it is supported by
153 //! both Clang and GCC. This operator allows Hana to provide the nice `_s`
154 //! user-defined literal for creating compile-time strings.
156 //! When this macro is not defined, the GNU extension will be not used
157 //! by Hana. Because this is a non-standard extension, the macro is not
158 //! defined by default.
159 # define BOOST_HANA_CONFIG_ENABLE_STRING_UDL
162 #if defined(BOOST_HANA_DOXYGEN_INVOKED)
163 //! @ingroup group-config
164 //! Enables additional assertions and sanity checks to be done by Hana.
166 //! When this macro is defined (it is __not defined__ by default),
167 //! additional sanity checks may be done by Hana. These checks may
168 //! be costly to perform, either in terms of compilation time or in
169 //! terms of execution time. These checks may help debugging an
170 //! application during its initial development, but they should not
171 //! be enabled as part of the normal configuration.
172 # define BOOST_HANA_CONFIG_ENABLE_DEBUG_MODE
175 #endif // !BOOST_HANA_CONFIG_HPP