forked from TartanLlama/optional
Support GCC 4.9
This commit is contained in:
@@ -76,6 +76,7 @@ Tested on:
|
|||||||
* clang 3.7
|
* clang 3.7
|
||||||
* clang 3.6
|
* clang 3.6
|
||||||
* g++ 5.0
|
* g++ 5.0
|
||||||
|
* g++ 4.9
|
||||||
- Appveyor continuous integration
|
- Appveyor continuous integration
|
||||||
* MSVC 2015
|
* MSVC 2015
|
||||||
* MSVC 2017
|
* MSVC 2017
|
||||||
@@ -85,7 +86,6 @@ Tested on:
|
|||||||
|
|
||||||
Unsupported, but planning to support:
|
Unsupported, but planning to support:
|
||||||
|
|
||||||
- g++ 4.9
|
|
||||||
- g++ 4.8
|
- g++ 4.8
|
||||||
|
|
||||||
|
|
||||||
|
33
optional.hpp
33
optional.hpp
@@ -17,7 +17,15 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#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
|
/// \exclude
|
||||||
#define TL_OPTIONAL_11_CONSTEXPR
|
#define TL_OPTIONAL_11_CONSTEXPR
|
||||||
#else
|
#else
|
||||||
@@ -25,13 +33,6 @@
|
|||||||
#define TL_OPTIONAL_11_CONSTEXPR constexpr
|
#define TL_OPTIONAL_11_CONSTEXPR constexpr
|
||||||
#endif
|
#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 {
|
namespace tl {
|
||||||
/// \brief Used to represent an optional with no data; essentially a bool
|
/// \brief Used to represent an optional with no data; essentially a bool
|
||||||
@@ -257,10 +258,10 @@ struct is_nothrow_swappable
|
|||||||
|
|
||||||
template <class T, bool = ::std::is_trivially_destructible<T>::value>
|
template <class T, bool = ::std::is_trivially_destructible<T>::value>
|
||||||
struct optional_storage_base {
|
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 <class... U>
|
template <class... U>
|
||||||
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>(u)...), m_has_value(true) {}
|
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
||||||
|
|
||||||
~optional_storage_base() {
|
~optional_storage_base() {
|
||||||
@@ -280,11 +281,11 @@ struct optional_storage_base {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <class T> struct optional_storage_base<T, true> {
|
template <class T> struct optional_storage_base<T, true> {
|
||||||
TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base() noexcept
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base() noexcept
|
||||||
: m_dummy(), m_has_value(false) {}
|
: m_dummy(), m_has_value(false) {}
|
||||||
|
|
||||||
template <class... U>
|
template <class... U>
|
||||||
TL_OPTIONAL_MSVC_2015_CONSTEXPR optional_storage_base(in_place_t,
|
TL_OPTIONAL_11_CONSTEXPR optional_storage_base(in_place_t,
|
||||||
U &&... u) noexcept
|
U &&... u) noexcept
|
||||||
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
: m_value(std::forward<U>(u)...), m_has_value(true) {}
|
||||||
|
|
||||||
@@ -560,7 +561,7 @@ public:
|
|||||||
/// \group or_else
|
/// \group or_else
|
||||||
/// \synopsis template <class F> optional<T> or_else (F &&f) &;
|
/// \synopsis template <class F> optional<T> or_else (F &&f) &;
|
||||||
template <class F, detail::enable_if_ret_void<F> * = nullptr>
|
template <class F, detail::enable_if_ret_void<F> * = nullptr>
|
||||||
optional<T> TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) & {
|
optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) & {
|
||||||
if (has_value())
|
if (has_value())
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
@@ -570,7 +571,7 @@ public:
|
|||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
||||||
optional<T> TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) & {
|
optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) & {
|
||||||
return has_value() ? *this : std::forward<F>(f)();
|
return has_value() ? *this : std::forward<F>(f)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +588,7 @@ public:
|
|||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
||||||
optional<T> TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) && {
|
optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) && {
|
||||||
return has_value() ? std::move(*this) : std::forward<F>(f)();
|
return has_value() ? std::move(*this) : std::forward<F>(f)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,7 +605,7 @@ public:
|
|||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
template <class F, detail::disable_if_ret_void<F> * = nullptr>
|
||||||
optional<T> TL_OPTIONAL_MSVC_2015_CONSTEXPR or_else(F &&f) const & {
|
optional<T> TL_OPTIONAL_11_CONSTEXPR or_else(F &&f) const & {
|
||||||
return has_value() ? *this : std::forward<F>(f)();
|
return has_value() ? *this : std::forward<F>(f)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
REQUIRE(e);
|
REQUIRE(e);
|
||||||
|
|
||||||
TEST_CASE("Constexpr", "[constexpr]") {
|
TEST_CASE("Constexpr", "[constexpr]") {
|
||||||
#if !(_MSC_VER == 1900)
|
#if !defined(TL_OPTIONAL_MSVC2015) && !defined(TL_OPTIONAL_GCC49)
|
||||||
SECTION("empty construct") {
|
SECTION("empty construct") {
|
||||||
constexpr tl::optional<int> o2{};
|
constexpr tl::optional<int> o2{};
|
||||||
constexpr tl::optional<int> o3 = {};
|
constexpr tl::optional<int> o3 = {};
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
REQUIRE(e);
|
REQUIRE(e);
|
||||||
|
|
||||||
constexpr int get_int(int) { return 42; }
|
constexpr int get_int(int) { return 42; }
|
||||||
TL_OPTIONAL_MSVC_2015_CONSTEXPR tl::optional<int> get_opt_int(int) { return 42; }
|
TL_OPTIONAL_11_CONSTEXPR tl::optional<int> get_opt_int(int) { return 42; }
|
||||||
|
|
||||||
// What is Clang Format up to?!
|
// What is Clang Format up to?!
|
||||||
TEST_CASE("Monadic operations",
|
TEST_CASE("Monadic operations",
|
||||||
@@ -193,7 +193,7 @@ REQUIRE(!o39r);
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("map constexpr") {
|
SECTION("map constexpr") {
|
||||||
#ifndef _MSC_VER
|
#if !defined(_MSC_VER) && !defined(TL_OPTIONAL_GCC49)
|
||||||
// test each overload in turn
|
// test each overload in turn
|
||||||
constexpr tl::optional<int> o16 = 42;
|
constexpr tl::optional<int> o16 = 42;
|
||||||
constexpr auto o16r = o16.map(get_int);
|
constexpr auto o16r = o16.map(get_int);
|
||||||
@@ -320,7 +320,7 @@ SECTION("and_then") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("constexpr and_then") {
|
SECTION("constexpr and_then") {
|
||||||
#ifndef _MSC_VER
|
#if !defined(_MSC_VER) && !defined(TL_OPTIONAL_GCC49)
|
||||||
constexpr tl::optional<int> o10 = 42;
|
constexpr tl::optional<int> o10 = 42;
|
||||||
constexpr auto o10r = o10.and_then(get_opt_int);
|
constexpr auto o10r = o10.and_then(get_opt_int);
|
||||||
REQUIRE(*o10r == 42);
|
REQUIRE(*o10r == 42);
|
||||||
|
Reference in New Issue
Block a user