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/containers/intrusive_list.hpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'asl/containers/intrusive_list.hpp') diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp index dcf0508..99509b8 100644 --- a/asl/containers/intrusive_list.hpp +++ b/asl/containers/intrusive_list.hpp @@ -76,14 +76,16 @@ public: } } - constexpr T* head() const + constexpr auto head(this auto&& self) { - return m_head; + using return_type = un_ref_t>*; + return return_type{ self.m_head }; } - constexpr T* tail() const + constexpr auto tail(this auto&& self) { - return m_head != nullptr ? m_head->m_prev : nullptr; + using return_type = un_ref_t>*; + return return_type{ self.m_head != nullptr ? self.m_head->m_prev : nullptr }; } void detach(T* node) @@ -169,25 +171,16 @@ public: using iterator = generic_iterator; using const_iterator = generic_iterator; - // @Todo(C++23) Deduplicate with deducing-this maybe - const_iterator begin() const + auto begin(this auto&& self) { - return const_iterator{ head(), is_empty() }; - } - - const_iterator end() const - { - return const_iterator{ head(), true }; + using iterator_type = select_t>, const_iterator, iterator>; + return iterator_type{ self.head(), self.is_empty() }; } - iterator begin() - { - return iterator{ head(), is_empty() }; - } - - iterator end() + auto end(this auto&& self) { - return iterator{ head(), true }; + using iterator_type = select_t>, const_iterator, iterator>; + return iterator_type{ self.head(), true }; } }; -- cgit