From 8034ce643d36e8cbe4c4d6bc9e154aaf2eb08597 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 26 Feb 2025 00:14:00 +0100 Subject: Use deducing-this in some places --- asl/types/option.hpp | 77 ++++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 56 deletions(-) (limited to 'asl/types/option.hpp') diff --git a/asl/types/option.hpp b/asl/types/option.hpp index 5cbb759..e79c09c 100644 --- a/asl/types/option.hpp +++ b/asl/types/option.hpp @@ -395,70 +395,35 @@ public: return value(); } - template - constexpr auto and_then(F&& f) & - requires is_option> - { - if (has_value()) - { - return invoke(ASL_FWD(f), value()); - } - return un_cvref_t>{}; - } - - template - constexpr auto and_then(F&& f) const& - requires is_option> - { - if (has_value()) - { - return invoke(ASL_FWD(f), value()); - } - return un_cvref_t>{}; - } - - template - constexpr auto and_then(F&& f) && - requires is_option> - { - if (has_value()) - { - return invoke(ASL_FWD(f), ASL_MOVE(value())); - } - return un_cvref_t>{}; - } - - template - constexpr auto transform(F&& f) & - { - using U = un_cvref_t>; - if (has_value()) - { - return option{ invoke(ASL_FWD(f), value()) }; - } - return option{}; - } - - template - constexpr auto transform(F&& f) const& + template< + typename F, + typename Self, + typename Result = result_of_t)> + > + constexpr auto and_then(this Self&& self, F&& f) + requires is_option { - using U = un_cvref_t>; - if (has_value()) + if (self.has_value()) { - return option{ invoke(ASL_FWD(f), value()) }; + return invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value())); } - return option{}; + return Result{ asl::nullopt }; } - template - constexpr auto transform(F&& f) && + template< + typename F, + typename Self, + typename Result = result_of_t)> + > + constexpr auto transform(this Self&& self, F&& f) { - using U = un_cvref_t>; - if (has_value()) + if (self.has_value()) { - return option{ invoke(ASL_FWD(f), ASL_MOVE(value())) }; + return option>{ + invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value())) + }; } - return option{}; + return option>{ asl::nullopt }; } template -- cgit