diff --git a/tl/expected.hpp b/tl/expected.hpp index 6b1adb4..13570bd 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -153,68 +153,53 @@ public: constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {} - /// \returns the contained value - /// \group unexpected_value + /// Returns the contained value constexpr const E &value() const & { return m_val; } - /// \group unexpected_value TL_EXPECTED_11_CONSTEXPR E &value() & { return m_val; } - /// \group unexpected_value TL_EXPECTED_11_CONSTEXPR E &&value() && { return std::move(m_val); } - /// \exclude constexpr const E &&value() const && { return std::move(m_val); } private: E m_val; }; -/// \brief Compares two unexpected objects -/// \details Simply compares lhs.value() to rhs.value() -/// \group unexpected_relop +/// Compares two unexpected objects template constexpr bool operator==(const unexpected &lhs, const unexpected &rhs) { return lhs.value() == rhs.value(); } -/// \group unexpected_relop template constexpr bool operator!=(const unexpected &lhs, const unexpected &rhs) { return lhs.value() != rhs.value(); } -/// \group unexpected_relop template constexpr bool operator<(const unexpected &lhs, const unexpected &rhs) { return lhs.value() < rhs.value(); } -/// \group unexpected_relop template constexpr bool operator<=(const unexpected &lhs, const unexpected &rhs) { return lhs.value() <= rhs.value(); } -/// \group unexpected_relop template constexpr bool operator>(const unexpected &lhs, const unexpected &rhs) { return lhs.value() > rhs.value(); } -/// \group unexpected_relop template constexpr bool operator>=(const unexpected &lhs, const unexpected &rhs) { return lhs.value() >= rhs.value(); } /// Create an `unexpected` from `e`, deducing the return type -/// -/// *Example:* -/// auto e1 = tl::make_unexpected(42); -/// unexpected e2 (42); //same semantics template unexpected::type> make_unexpected(E &&e) { return unexpected::type>(std::forward(e)); } -/// \brief A tag type to tell expected to construct the unexpected value +/// A tag type to tell expected to construct the unexpected value struct unexpect_t { unexpect_t() = default; }; -/// \brief A tag to tell expected to construct the unexpected value +/// A tag to tell expected to construct the unexpected value static constexpr unexpect_t unexpect{}; /// \exclude @@ -1329,66 +1314,33 @@ public: #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) - /// \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())`. If `U` is `void`, returns an `expected, otherwise - // returns an `expected`. If `*this` is unexpected, the - /// result is `*this`, otherwise an `expected` is constructed from the - /// return value of `std::invoke(std::forward(f), value())` and is - /// returned. - /// - /// \group map - /// \synopsis template constexpr auto map(F &&f) &; - template TL_EXPECTED_11_CONSTEXPR auto map(F &&f) & { + /// Carries out some operation on the stored object if there is one. + template TL_EXPECTED_11_CONSTEXPR auto map(F &&f) & { return expected_map_impl(*this, std::forward(f)); } - - /// \group map - /// \synopsis template constexpr auto map(F &&f) &&; template TL_EXPECTED_11_CONSTEXPR auto map(F &&f) && { return expected_map_impl(std::move(*this), std::forward(f)); } - - /// \group map - /// \synopsis template constexpr auto map(F &&f) const &; template constexpr auto map(F &&f) const & { return expected_map_impl(*this, std::forward(f)); } - - /// \group map - /// \synopsis template constexpr auto map(F &&f) const &&; template constexpr auto map(F &&f) const && { return expected_map_impl(std::move(*this), std::forward(f)); } #else - /// \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())`. If `U` is `void`, returns an `expected, otherwise - // returns an `expected`. If `*this` is unexpected, the - /// result is `*this`, otherwise an `expected` is constructed from the - /// return value of `std::invoke(std::forward(f), value())` and is - /// returned. - /// - /// \group map - /// \synopsis template constexpr auto map(F &&f) &; + /// Carries out some operation on the stored object if there is one. template TL_EXPECTED_11_CONSTEXPR decltype( expected_map_impl(std::declval(), std::declval())) map(F &&f) & { return expected_map_impl(*this, std::forward(f)); } - - /// \group map - /// \synopsis template constexpr auto map(F &&f) &&; template TL_EXPECTED_11_CONSTEXPR decltype( expected_map_impl(std::declval(), std::declval())) map(F &&f) && { return expected_map_impl(std::move(*this), std::forward(f)); } - - /// \group map - /// \synopsis template constexpr auto map(F &&f) const &; template constexpr decltype(expected_map_impl(std::declval(), std::declval())) @@ -1397,8 +1349,6 @@ public: } #ifndef TL_EXPECTED_NO_CONSTRR - /// \group map - /// \synopsis template constexpr auto map(F &&f) const &&; template constexpr decltype(expected_map_impl(std::declval(), std::declval())) @@ -1408,6 +1358,52 @@ public: #endif #endif +#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ + !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) + /// Carries out some operation on the stored object if there is one. + template TL_EXPECTED_11_CONSTEXPR auto transform(F &&f) & { + return expected_map_impl(*this, std::forward(f)); + } + template TL_EXPECTED_11_CONSTEXPR auto transform(F &&f) && { + return expected_map_impl(std::move(*this), std::forward(f)); + } + template constexpr auto transform(F &&f) const & { + return expected_map_impl(*this, std::forward(f)); + } + template constexpr auto transform(F &&f) const && { + return expected_map_impl(std::move(*this), std::forward(f)); + } +#else + /// Carries out some operation on the stored object if there is one. + template + TL_EXPECTED_11_CONSTEXPR decltype( + expected_map_impl(std::declval(), std::declval())) + transform(F &&f) & { + return expected_map_impl(*this, std::forward(f)); + } + template + TL_EXPECTED_11_CONSTEXPR decltype( + expected_map_impl(std::declval(), std::declval())) + transform(F &&f) && { + return expected_map_impl(std::move(*this), std::forward(f)); + } + template + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) + transform(F &&f) const & { + return expected_map_impl(*this, std::forward(f)); + } + +#ifndef TL_EXPECTED_NO_CONSTRR + template + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) + transform(F &&f) const && { + return expected_map_impl(std::move(*this), std::forward(f)); + } +#endif +#endif + #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) /// \brief Carries out some operation on the stored unexpected object if there