diff --git a/README.md b/README.md index 83f1b66..1c5d9c5 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Tested on: * clang 3.7 * clang 3.6 * g++ 5.0 + * g++ 4.9 - Appveyor continuous integration * MSVC 2015 * MSVC 2017 @@ -85,7 +86,6 @@ Tested on: Unsupported, but planning to support: -- g++ 4.9 - g++ 4.8 diff --git a/optional.hpp b/optional.hpp index 0a58569..fb27242 100644 --- a/optional.hpp +++ b/optional.hpp @@ -17,7 +17,15 @@ #include #include -#if __cplusplus == 201103L || (defined(_MSC_VER) && _MSC_VER == 1900) +#if (defined(_MSC_VER) && _MSC_VER == 1900) +#define TL_OPTIONAL_MSVC2015 +#endif + +#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9) +#define TL_OPTIONAL_GCC49 +#endif + +#if __cplusplus == 201103L || defined(TL_OPTIONAL_MSVC2015) || defined(TL_OPTIONAL_GCC49) /// \exclude #define TL_OPTIONAL_11_CONSTEXPR #else @@ -25,13 +33,6 @@ #define TL_OPTIONAL_11_CONSTEXPR constexpr #endif -#if defined(_MSC_VER) && _MSC_VER == 1900 -/// \exclude -#define TL_OPTIONAL_MSVC_2015_CONSTEXPR -#else -/// \exclude -#define TL_OPTIONAL_MSVC_2015_CONSTEXPR constexpr -#endif namespace tl { /// \brief Used to represent an optional with no data; essentially a bool @@ -257,10 +258,10 @@ struct is_nothrow_swappable template ::value> struct optional_storage_base { - TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base() noexcept : m_dummy(), m_has_value(false) {} + TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept : m_dummy(), m_has_value(false) {} template - TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base(in_place_t, U &&... u) noexcept + TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u) noexcept : m_value(std::forward(u)...), m_has_value(true) {} ~optional_storage_base() { @@ -280,11 +281,11 @@ struct optional_storage_base { }; template struct optional_storage_base { - TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base() noexcept + TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept : m_dummy(), m_has_value(false) {} template - TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base(in_place_t, + TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t, U &&... u) noexcept : m_value(std::forward(u)...), m_has_value(true) {} @@ -560,7 +561,7 @@ public: /// \group or_else /// \synopsis template optional or_else (F &&f) &; template * = nullptr> - optional TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) & { + optional TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) & { if (has_value()) return *this; @@ -570,7 +571,7 @@ public: /// \exclude template * = nullptr> - optional TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) & { + optional TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) & { return has_value() ? *this : std::forward(f)(); } @@ -587,7 +588,7 @@ public: /// \exclude template * = nullptr> - optional TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) && { + optional TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) && { return has_value() ? std::move(*this) : std::forward(f)(); } @@ -604,7 +605,7 @@ public: /// \exclude template * = nullptr> - optional TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) const & { + optional TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) const & { return has_value() ? *this : std::forward(f)(); } diff --git a/tests/constexpr.cpp b/tests/constexpr.cpp index c95f3d8..9dabfd1 100644 --- a/tests/constexpr.cpp +++ b/tests/constexpr.cpp @@ -8,7 +8,7 @@ REQUIRE(e); TEST_CASE("Constexpr", "[constexpr]") { -#if !(_MSC_VER == 1900) +#if !defined(TL_OPTIONAL_MSVC2015) && !defined(TL_OPTIONAL_GCC49) SECTION("empty construct") { constexpr tl::optional o2{}; constexpr tl::optional o3 = {}; diff --git a/tests/extensions.cpp b/tests/extensions.cpp index 018bbc2..f4983ab 100644 --- a/tests/extensions.cpp +++ b/tests/extensions.cpp @@ -9,7 +9,7 @@ REQUIRE(e); constexpr int get_int(int) { return 42; } -TL_OPTIONAL_MSVC_2015_CONSTEXPR tl::optional get_opt_int(int) { return 42; } +TL_OPTIONAL_11_CONSTEXPR tl::optional get_opt_int(int) { return 42; } // What is Clang Format up to?! TEST_CASE("Monadic operations", @@ -193,7 +193,7 @@ REQUIRE(!o39r); } SECTION("map constexpr") { -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(TL_OPTIONAL_GCC49) // test each overload in turn constexpr tl::optional o16 = 42; constexpr auto o16r = o16.map(get_int); @@ -320,7 +320,7 @@ SECTION("and_then") { } SECTION("constexpr and_then") { -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(TL_OPTIONAL_GCC49) constexpr tl::optional o10 = 42; constexpr auto o10r = o10.and_then(get_opt_int); REQUIRE(*o10r == 42);