summaryrefslogtreecommitdiff
path: root/asl/types/option.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-26 00:14:00 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-26 00:14:00 +0100
commit8034ce643d36e8cbe4c4d6bc9e154aaf2eb08597 (patch)
treebd8b8078347aeb7604935fffa9423d575f45cf0e /asl/types/option.hpp
parent8b112960586fce4aad791f9cf52c94a70b476ce0 (diff)
Use deducing-this in some places
Diffstat (limited to 'asl/types/option.hpp')
-rw-r--r--asl/types/option.hpp77
1 files changed, 21 insertions, 56 deletions
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<typename F>
- constexpr auto and_then(F&& f) &
- requires is_option<result_of_t<F(T&)>>
- {
- if (has_value())
- {
- return invoke(ASL_FWD(f), value());
- }
- return un_cvref_t<result_of_t<F(T&)>>{};
- }
-
- template<typename F>
- constexpr auto and_then(F&& f) const&
- requires is_option<result_of_t<F(const T&)>>
- {
- if (has_value())
- {
- return invoke(ASL_FWD(f), value());
- }
- return un_cvref_t<result_of_t<F(const T&)>>{};
- }
-
- template<typename F>
- constexpr auto and_then(F&& f) &&
- requires is_option<result_of_t<F(T)>>
- {
- if (has_value())
- {
- return invoke(ASL_FWD(f), ASL_MOVE(value()));
- }
- return un_cvref_t<result_of_t<F(T)>>{};
- }
-
- template<typename F>
- constexpr auto transform(F&& f) &
- {
- using U = un_cvref_t<result_of_t<F(T&)>>;
- if (has_value())
- {
- return option<U>{ invoke(ASL_FWD(f), value()) };
- }
- return option<U>{};
- }
-
- template<typename F>
- constexpr auto transform(F&& f) const&
+ template<
+ typename F,
+ typename Self,
+ typename Result = result_of_t<F(copy_cref_t<Self&&, T>)>
+ >
+ constexpr auto and_then(this Self&& self, F&& f)
+ requires is_option<Result>
{
- using U = un_cvref_t<result_of_t<F(const T&)>>;
- if (has_value())
+ if (self.has_value())
{
- return option<U>{ invoke(ASL_FWD(f), value()) };
+ return invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value()));
}
- return option<U>{};
+ return Result{ asl::nullopt };
}
- template<typename F>
- constexpr auto transform(F&& f) &&
+ template<
+ typename F,
+ typename Self,
+ typename Result = result_of_t<F(copy_cref_t<Self&&, T>)>
+ >
+ constexpr auto transform(this Self&& self, F&& f)
{
- using U = un_cvref_t<result_of_t<F(T)>>;
- if (has_value())
+ if (self.has_value())
{
- return option<U>{ invoke(ASL_FWD(f), ASL_MOVE(value())) };
+ return option<un_cvref_t<Result>>{
+ invoke(ASL_FWD(f), ASL_FWD_LIKE(decltype(self), ASL_FWD(self).value()))
+ };
}
- return option<U>{};
+ return option<un_cvref_t<Result>>{ asl::nullopt };
}
template<typename F>