From f0ba0990eaf5f19ba4deffc935363d03f1326f50 Mon Sep 17 00:00:00 2001 From: Janusz Lewandowski Date: Sat, 27 Jul 2013 19:11:41 +0200 Subject: [PATCH 1/2] Add support for gcc 4.6. --- README.md | 2 +- optional.hpp | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 883c1d1..35a8454 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A library for optional (nullable) objects for C++11. This is the reference imple Supported compilers ------------------- -Clang 3.2, G++ 4.7.2 (and probably later) +Clang 3.2, G++ 4.6+ Usage diff --git a/optional.hpp b/optional.hpp index c6107fb..504dbd4 100644 --- a/optional.hpp +++ b/optional.hpp @@ -21,36 +21,43 @@ # define REQUIRES(...) typename enable_if<__VA_ARGS__::value, bool>::type = false # if defined __clang__ +# define OPTIONAL_HAS_USING 1 # if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) # define OPTIONAL_HAS_THIS_RVALUE_REFS 1 # else # define OPTIONAL_HAS_THIS_RVALUE_REFS 0 # endif # elif defined __GNUC__ -# if (__GNUC__ >= 4) && (__GNUC_MINOR__ > 8 || ((__GNUC_MINOR__ >= 8) && (__GNUC_PATCHLEVEL__ >= 1))) +# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) +# define OPTIONAL_HAS_USING 1 +# else +# define OPTIONAL_HAS_USING 0 +# endif +# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 8 || ((__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1)))) # define OPTIONAL_HAS_THIS_RVALUE_REFS 1 # else # define OPTIONAL_HAS_THIS_RVALUE_REFS 0 # endif # else # define OPTIONAL_HAS_THIS_RVALUE_REFS 0 +# define OPTIONAL_HAS_USING 0 # endif namespace std{ -# if (defined __GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 8) +# if (defined __GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) // leave it; our metafunctions are already defined. # else - +# if OPTIONAL_HAS_USING // the only bit GCC 4.7 and clang(?) don't have template using is_trivially_destructible = typename std::has_trivial_destructor; +# endif - -# if (defined __GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7) +# if (defined __GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))) // leave it; remaining metafunctions are already defined. # elif defined __clang__ // leave it; remaining metafunctions are already defined. @@ -295,14 +302,16 @@ struct constexpr_optional_base ~constexpr_optional_base() = default; }; +# if OPTIONAL_HAS_USING template using OptionalBase = typename std::conditional< std::is_trivially_destructible::value, constexpr_optional_base, optional_base >::type; - - +# else +# define OptionalBase optional_base +# endif template class optional : private OptionalBase @@ -930,6 +939,8 @@ namespace std }; } - +#ifdef OptionalBase +# undef OptionalBase +#endif # endif //___OPTIONAL_HPP___ From 0dc7d9b1546fcbd7b90caa48423e2e97f4569245 Mon Sep 17 00:00:00 2001 From: Janusz Lewandowski Date: Sat, 27 Jul 2013 19:14:46 +0200 Subject: [PATCH 2/2] Add support for clang 3.3. --- README.md | 2 +- optional.hpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35a8454..e7fcb11 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A library for optional (nullable) objects for C++11. This is the reference imple Supported compilers ------------------- -Clang 3.2, G++ 4.6+ +Clang 3.2+, G++ 4.6+ Usage diff --git a/optional.hpp b/optional.hpp index 504dbd4..a787cc8 100644 --- a/optional.hpp +++ b/optional.hpp @@ -49,10 +49,12 @@ namespace std{ # if (defined __GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))) // leave it; our metafunctions are already defined. +# elif (defined __clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3) && (__clang_minor__ >= 3)) + // leave it; our metafunctions are already defined. # else # if OPTIONAL_HAS_USING -// the only bit GCC 4.7 and clang(?) don't have +// the only bit GCC 4.7 and clang 3.2 don't have template using is_trivially_destructible = typename std::has_trivial_destructor; # endif