From 38ab48b1882f36ed7eb7e50c4fb46ce5d376fbc3 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 26 Feb 2025 20:01:45 +0100 Subject: Fix some deducing-this & functional stuff, add invocable concept --- asl/types/option.hpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'asl/types/option.hpp') diff --git a/asl/types/option.hpp b/asl/types/option.hpp index e79c09c..b32483b 100644 --- a/asl/types/option.hpp +++ b/asl/types/option.hpp @@ -395,32 +395,27 @@ public: return value(); } - template< - typename F, - typename Self, - typename Result = result_of_t)> - > + template constexpr auto and_then(this Self&& self, F&& f) - requires is_option { + using Result = invoke_result_t>; + static_assert(is_option); + if (self.has_value()) { - return invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value())); + return invoke(ASL_FWD(f), ASL_FWD(self).value()); } return Result{ asl::nullopt }; } - template< - typename F, - typename Self, - typename Result = result_of_t)> - > + template constexpr auto transform(this Self&& self, F&& f) { + using Result = invoke_result_t>; if (self.has_value()) { return option>{ - invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value())) + invoke(ASL_FWD(f), ASL_FWD(self).value()) }; } return option>{ asl::nullopt }; @@ -428,14 +423,14 @@ public: template constexpr option or_else(F&& f) const& - requires same_as>, option> + requires same_as>, option> { return has_value() ? *this : invoke(ASL_FWD(f)); } template constexpr option or_else(F&& f) && - requires same_as>, option> + requires same_as>, option> { return has_value() ? ASL_MOVE(*this) : invoke(ASL_FWD(f)); } -- cgit