diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-11-22 13:19:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-11-22 13:19:08 +0200 |
commit | a5cd8c15a9a44858d91bbadbaed30173e79f9a5a (patch) | |
tree | 81d5339fb97a45352564a240c2e8730283bc6190 | |
parent | 4aeb5d497494eac5383610ae5dc0b70645f8ab21 (diff) |
Switch to std::optional in more configurations
-rw-r--r-- | libbutl/optional.mxx | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/libbutl/optional.mxx b/libbutl/optional.mxx index 87ba361..33ee3d3 100644 --- a/libbutl/optional.mxx +++ b/libbutl/optional.mxx @@ -8,18 +8,46 @@ // C includes. -// Note: Clang must come first (also defines __GNUC__). +// Note: the Clang check must come before GCC since also defines __GNUC__. // -// @@ Clang might be using libstdc++ without optional (feature test macro?) -// @@ Move to /ft/? -// -// Note: make sure we use butl::optional during ODB compilation (has to be -// this way until we completely switch to std::optional). -// -#if !defined(ODB_COMPILER) && \ - __cplusplus >= 201703L && \ - defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__) -# define LIBBUTL_STD_OPTIONAL +#if defined(ODB_COMPILER) + // + // Make sure we use butl::optional during ODB compilation (has to be this + // way until we completely switch to std::optional since we use the same + // generated code for all compiler). + // +#elif defined(_MSC_VER) + // + // Available from 19.10 (15.0). Except it (or the compiler) doesn't seem to + // be constexpr-correct. Let's re-test with 16.0. + // +# if _MSC_VER > 1916 +# define LIBBUTL_STD_OPTIONAL +# endif +#elif defined(__clang__) + // + // Clang's libc++ has it since 4 but we might also be using libstdc++. For + // the latter we will check for the presence of the <optional> header which + // only appeared in GCC 7. Also assume both are only available in C++17. + // +# if __cplusplus >= 201703L +# if __has_include(<__config>) +# include <__config> // _LIBCPP_VERSION +# if _LIBCPP_VERSION >= 4000 +# define LIBBUTL_STD_OPTIONAL +# endif +# elif __has_include(<optional>) +# define LIBBUTL_STD_OPTIONAL +# endif +# endif +#elif defined(__GNUC__) + // + // Available from 7 but only in the C++17 mode. Note also that from 8 + // <optional> defines __cpp_lib_optional. + // +# if __GNUC__ >= 7 && __cplusplus >= 201703L +# define LIBBUTL_STD_OPTIONAL +# endif #endif #ifndef __cpp_lib_modules |