From b5d224496ffb1649026944f73989c4a97f6283bd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 11 Nov 2022 09:18:15 +0100 Subject: [PATCH] util/IntrusiveList: iterators are bidirectional --- src/util/IntrusiveList.hxx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 76d2ae1b7..3910dab09 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -372,7 +372,7 @@ public: :cursor(_cursor) {} public: - using iterator_category = std::forward_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using value_type = T; using difference_type = std::ptrdiff_t; using pointer = value_type *; @@ -400,6 +400,17 @@ public: cursor = cursor->next; return *this; } + + iterator &operator--() noexcept { + cursor = cursor->prev; + return *this; + } + + iterator &operator--(int) noexcept { + auto old = *this; + cursor = cursor->prev; + return old; + } }; constexpr iterator begin() noexcept { @@ -423,7 +434,7 @@ public: :cursor(_cursor) {} public: - using iterator_category = std::forward_iterator_tag; + using iterator_category = std::bidirectional_iterator_tag; using value_type = const T; using difference_type = std::ptrdiff_t; using pointer = value_type *; @@ -454,6 +465,17 @@ public: cursor = cursor->next; return *this; } + + iterator &operator--() noexcept { + cursor = cursor->prev; + return *this; + } + + iterator &operator--(int) noexcept { + auto old = *this; + cursor = cursor->prev; + return old; + } }; constexpr const_iterator begin() const noexcept {