From eb285643ed5dab8125e9c6bc94abd7ef562096a5 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 27 Feb 2025 23:58:57 +0100 Subject: Finish work on deducing this, for now --- asl/types/maybe_uninit.hpp | 20 ++++++++------------ asl/types/option.hpp | 20 +++++++++----------- asl/types/status_or.hpp | 3 +-- 3 files changed, 18 insertions(+), 25 deletions(-) (limited to 'asl/types') diff --git a/asl/types/maybe_uninit.hpp b/asl/types/maybe_uninit.hpp index 36429e4..e8ccbd3 100644 --- a/asl/types/maybe_uninit.hpp +++ b/asl/types/maybe_uninit.hpp @@ -17,9 +17,8 @@ public: constexpr maybe_uninit() requires trivially_default_constructible = default; constexpr maybe_uninit() requires (!trivially_default_constructible) {} // NOLINT - template - explicit constexpr maybe_uninit(in_place_t, Args&&... args) - requires constructible_from + explicit constexpr maybe_uninit(in_place_t, auto&&... args) + requires constructible_from : m_value{ASL_FWD(args)...} {} @@ -39,17 +38,15 @@ public: constexpr ~maybe_uninit() requires (!trivially_destructible) {} // NOLINT // @Safety Value must not have been initialized yet - template - constexpr void construct_unsafe(Args&&... args) - requires constructible_from + constexpr void construct_unsafe(auto&&... args) + requires constructible_from { construct_at(&m_value, ASL_FWD(args)...); } // @Safety Value must have been initialized - template - constexpr void assign_unsafe(U&& value) - requires assignable_from + constexpr void assign_unsafe(auto&& value) + requires assignable_from { m_value = ASL_FWD(value); } @@ -64,10 +61,9 @@ public: } // @Safety Value must have been initialized - template - constexpr auto&& as_init_unsafe(this Self&& self) + constexpr auto&& as_init_unsafe(this auto&& self) { - return ASL_FWD_LIKE(decltype(self), ASL_FWD(self).m_value); + return ASL_FWD(self).m_value; } }; diff --git a/asl/types/option.hpp b/asl/types/option.hpp index b32483b..8b5f313 100644 --- a/asl/types/option.hpp +++ b/asl/types/option.hpp @@ -365,8 +365,7 @@ public: } } - template - constexpr auto&& value(this Self&& self) + constexpr auto&& value(this auto&& self) { ASL_ASSERT_RELEASE(self.has_value()); return ASL_FWD(self).m_payload.as_init_unsafe(); @@ -386,19 +385,18 @@ public: return has_value() ? ASL_MOVE(value()) : static_cast(ASL_FWD(other_value)); } - template - constexpr T& emplace(Args&&... args) & - requires constructible_from + constexpr T& emplace(auto&&... args) & + requires constructible_from { if (has_value()) { reset(); } construct(ASL_FWD(args)...); return value(); } - template - constexpr auto and_then(this Self&& self, F&& f) + template + constexpr auto and_then(this auto&& self, F&& f) { - using Result = invoke_result_t>; + using Result = invoke_result_t>; static_assert(is_option); if (self.has_value()) @@ -408,10 +406,10 @@ public: return Result{ asl::nullopt }; } - template - constexpr auto transform(this Self&& self, F&& f) + template + constexpr auto transform(this auto&& self, F&& f) { - using Result = invoke_result_t>; + using Result = invoke_result_t>; if (self.has_value()) { return option>{ diff --git a/asl/types/status_or.hpp b/asl/types/status_or.hpp index 5771d58..a8a48c1 100644 --- a/asl/types/status_or.hpp +++ b/asl/types/status_or.hpp @@ -129,8 +129,7 @@ public: constexpr status&& throw_status() && { return ASL_MOVE(m_status); } - template - constexpr auto&& value(this Self&& self) + constexpr auto&& value(this auto&& self) { ASL_ASSERT_RELEASE(self.ok()); return ASL_FWD(self).m_value.as_init_unsafe(); -- cgit