diff options
Diffstat (limited to 'asl/containers/intrusive_list.hpp')
-rw-r--r-- | asl/containers/intrusive_list.hpp | 31 |
1 files changed, 12 insertions, 19 deletions
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<copy_cref_t<decltype(self), 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<copy_cref_t<decltype(self), 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<T>; using const_iterator = generic_iterator<const T>; - // @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<is_const<un_ref_t<decltype(self)>>, 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<is_const<un_ref_t<decltype(self)>>, const_iterator, iterator>; + return iterator_type{ self.head(), true }; } }; |