[llvm] [ADT] Adding bidirectional iterator functionality + unit tests (PR #160726)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 09:09:08 PDT 2025


================
@@ -40,12 +40,20 @@ template <typename BitVectorT> class const_set_bits_iterator_impl {
     Current = Parent.find_next(Current);
   }
 
+  void retreat() {
+    if (Current == -1) {
+      Current = Parent.find_last();
+    } else {
+      Current = Parent.find_prev(Current);
+    }
+  }
+
 public:
-  using iterator_category = std::forward_iterator_tag;
+  using iterator_category = std::bidirectional_iterator_tag;
   using difference_type   = std::ptrdiff_t;
-  using value_type        = int;
-  using pointer           = value_type*;
-  using reference         = value_type&;
+  using value_type        = unsigned;
+  using pointer           = const value_type*;
+  using reference         = value_type;
----------------
kuhar wrote:

I think this technically no longer satisfies `forward_iterator` anymore, but we have the same issue with `enumerate` and it's fine in practise and won't become necessary with newer c++ anyway
https://github.com/llvm/llvm-project/blob/e2cab7c031c46a4465bd7380db64a8c87ec2b5e5/llvm/include/llvm/ADT/STLExtras.h#L2265-L2271

https://github.com/llvm/llvm-project/pull/160726


More information about the llvm-commits mailing list