From beedb23d5c4e1b341d03c83a9cf587583eb43652 Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Sat, 28 Oct 2017 14:16:50 +0100 Subject: [PATCH] Fix GCC --- expected.hpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/expected.hpp b/expected.hpp index f672b68..82396b2 100644 --- a/expected.hpp +++ b/expected.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #if (defined(_MSC_VER) && _MSC_VER == 1900) #define TL_EXPECTED_MSVC2015 @@ -432,7 +433,7 @@ public: typedef E error_type; typedef unexpected unexpected_type; -#ifdef TL_EXPECTED_CXX14 +#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && !defined(TL_EXPECTED_GCC54) /// \group and_then /// Carries out some operation which returns an optional on the stored object /// if there is one. \requires `std::invoke(std::forward(f), value())` @@ -544,9 +545,9 @@ public: : result(unexpect, std::move(this->error())); } #endif -#endif +#endif -#ifdef TL_EXPECTED_CXX14 +#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && !defined(TL_EXPECTED_GCC54) /// \brief Carries out some operation on the stored object if there is one. /// \returns Let `U` be the result of `std::invoke(std::forward(f), /// value())`. Returns a `std::expected`. The return value is empty if @@ -606,7 +607,7 @@ public: #endif #endif -#ifdef TL_EXPECTED_CXX14 +#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && !defined(TL_EXPECTED_GCC54) /// \brief Carries out some operation on the stored object if there is one. /// \returns Let `U` be the result of `std::invoke(std::forward(f), /// value())`. Returns a `std::expected`. The return value is empty if @@ -873,8 +874,9 @@ public: "T must be move-constructible and convertible to from U&&"); return bool(*this) ? std::move(**this) : static_cast(std::forward(v)); } +}; -private: + namespace detail { template using err_t = typename detail::decay_t::error_type; template using ret_t = expected>; @@ -883,7 +885,7 @@ private: class Ret = decltype(detail::invoke(std::declval(), *std::declval())), detail::enable_if_t::value> * = nullptr> - static constexpr auto map_impl(Exp &&exp, F &&f) { + constexpr auto map_impl(Exp &&exp, F &&f) { using result = ret_t; return exp.has_value() ? result(detail::invoke(std::forward(f), *std::forward(exp))) @@ -894,7 +896,7 @@ private: class Ret = decltype(detail::invoke(std::declval(), *std::declval())), detail::enable_if_t::value> * = nullptr> - static auto map_impl(Exp &&exp, F &&f) { + auto map_impl(Exp &&exp, F &&f) { using result = expected>; if (exp.has_value()) { detail::invoke(std::forward(f), *std::forward(exp)); @@ -909,7 +911,7 @@ private: *std::declval())), detail::enable_if_t::value> * = nullptr> - static constexpr auto map_impl(Exp &&exp, F &&f) -> ret_t { + constexpr auto map_impl(Exp &&exp, F &&f) -> ret_t { using result = ret_t; return exp.has_value() ? result(detail::invoke(std::forward(f), @@ -922,7 +924,7 @@ private: *std::declval())), detail::enable_if_t::value> * = nullptr> - static auto map_impl(Exp &&exp, F &&f) -> expected> { + auto map_impl(Exp &&exp, F &&f) -> expected> { if (exp.has_value()) { detail::invoke(std::forward(f), *std::forward(exp)); return tl::monostate{}; @@ -932,11 +934,11 @@ private: } #endif -#ifdef TL_EXPECTED_CXX14 +#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && !defined(TL_EXPECTED_GCC54) template (), *std::declval()))> - static constexpr auto map_error_impl(Exp &&exp, F &&f) { + constexpr auto map_error_impl(Exp &&exp, F &&f) { using result = ret_t; return exp.has_value() ? result(*std::forward(exp)) @@ -948,15 +950,17 @@ private: template (), *std::declval()))> - static constexpr auto map_error_impl(Exp &&exp, F &&f) -> ret_t { + constexpr auto map_error_impl(Exp &&exp, F &&f) -> ret_t { using result = ret_t; - return exp.has_value() ? result(detail::invoke(std::forward(f), - *std::forward(exp))) - : result(unexpect, std::forward(exp).error()); + return exp.has_value() + ? result(*std::forward(exp)) + : result(unexpect, + detail::invoke(std::forward(f), + std::forward(exp).error())); } #endif -}; + } // TODO template class expected {};