From 61d02f42eb307ec7ac84ae03caf1abeb661c1d83 Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Wed, 18 Feb 2026 16:38:11 +0000 Subject: [PATCH] Improve support for move only types --- include/pfn/expected.hpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/include/pfn/expected.hpp b/include/pfn/expected.hpp index 962c223..43cba35 100644 --- a/include/pfn/expected.hpp +++ b/include/pfn/expected.hpp @@ -275,22 +275,22 @@ template class expected { rhs.set_ = true; } - constexpr T const &_value() const & + constexpr T const &_value() const & noexcept { ASSERT(set_); return v_; } - constexpr T &_value() & + constexpr T &_value() & noexcept { ASSERT(set_); return v_; } - constexpr T const &&_value() const && + constexpr T const &&_value() const && noexcept { ASSERT(set_); return ::std::move(v_); } - constexpr T &&_value() && + constexpr T &&_value() && noexcept { ASSERT(set_); return ::std::move(v_); @@ -298,16 +298,16 @@ template class expected { template static constexpr auto _and_then(Self &&self, Fn &&fn) // - noexcept(::std::is_nothrow_invocable_v + noexcept(::std::is_nothrow_invocable_v && ::std::is_nothrow_constructible_v) - requires(::std::is_invocable_v + requires(::std::is_invocable_v && ::std::is_constructible_v) { - using result_t = ::std::remove_cvref_t<::std::invoke_result_t>; + using result_t = ::std::remove_cvref_t<::std::invoke_result_t>; static_assert(detail::_is_some_expected); static_assert(::std::is_same_v::error_type>); if (self.has_value()) { - return ::std::invoke(FWD(fn), FWD(self).value()); + return ::std::invoke(FWD(fn), FWD(self)._value()); } return result_t(unexpect, FWD(self).error()); } @@ -330,24 +330,24 @@ template class expected { template static constexpr auto _transform(Self &&self, Fn &&fn) // - noexcept(::std::is_nothrow_invocable_v + noexcept(::std::is_nothrow_invocable_v && ::std::is_nothrow_constructible_v - && (::std::is_void_v<::std::invoke_result_t> + && (::std::is_void_v<::std::invoke_result_t> || ::std::is_nothrow_constructible_v< - ::std::remove_cv_t<::std::invoke_result_t>, - ::std::invoke_result_t>)) - requires(::std::is_invocable_v + ::std::remove_cv_t<::std::invoke_result_t>, + ::std::invoke_result_t>)) + requires(::std::is_invocable_v && ::std::is_constructible_v) { - using value_t = ::std::remove_cv_t<::std::invoke_result_t>; + using value_t = ::std::remove_cv_t<::std::invoke_result_t>; static_assert(detail::_is_valid_expected); using result_t = expected; if (self.has_value()) { if constexpr (not ::std::is_void_v) { - static_assert(::std::is_constructible_v>); - return result_t(::std::in_place, ::std::invoke(FWD(fn), FWD(self).value())); + static_assert(::std::is_constructible_v>); + return result_t(::std::in_place, ::std::invoke(FWD(fn), FWD(self)._value())); } else { - ::std::invoke(FWD(fn), FWD(self).value()); + ::std::invoke(FWD(fn), FWD(self)._value()); return result_t(::std::in_place); } }