summaryrefslogtreecommitdiff
path: root/asl/containers/intrusive_list.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-27 23:58:57 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-28 00:30:34 +0100
commiteb285643ed5dab8125e9c6bc94abd7ef562096a5 (patch)
tree99bb67ae08b15d4de39a8a98b0f9c051dce97546 /asl/containers/intrusive_list.hpp
parent38ab48b1882f36ed7eb7e50c4fb46ce5d376fbc3 (diff)
Finish work on deducing this, for now
Diffstat (limited to 'asl/containers/intrusive_list.hpp')
-rw-r--r--asl/containers/intrusive_list.hpp31
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 };
}
};