[llvm] [ADT] Allow std::next to work on BitVector's set_bits_iterator (PR #80830)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 05:09:19 PST 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/80830
Without this I would hit errors with libstdc++-12 like:
/usr/include/c++/12/bits/stl_iterator_base_funcs.h:230:5: note: candidate template ignored: substitution failure [with _InputIterator = llvm::const_set_bits_iterator_impl<llvm::BitVector>]: argument may not have 'void' type
next(_InputIterator __x, typename
^
>From cf599172f1cfbda42db420d8babd1c4b3bf47950 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Tue, 6 Feb 2024 12:51:27 +0000
Subject: [PATCH] [ADT] Allow std::next to work on BitVector's
set_bits_iterator
Without this I would hit errors with libstdc++-12 like:
/usr/include/c++/12/bits/stl_iterator_base_funcs.h:230:5: note: candidate template ignored: substitution failure [with _InputIterator = llvm::const_set_bits_iterator_impl<llvm::BitVector>]: argument may not have 'void' type
next(_InputIterator __x, typename
^
---
llvm/include/llvm/ADT/BitVector.h | 2 +-
llvm/unittests/ADT/BitVectorTest.cpp | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h
index e0de1afcc9418..0eaa77b6dd81c 100644
--- a/llvm/include/llvm/ADT/BitVector.h
+++ b/llvm/include/llvm/ADT/BitVector.h
@@ -42,7 +42,7 @@ template <typename BitVectorT> class const_set_bits_iterator_impl {
public:
using iterator_category = std::forward_iterator_tag;
- using difference_type = void;
+ using difference_type = std::ptrdiff_t;
using value_type = int;
using pointer = value_type*;
using reference = value_type&;
diff --git a/llvm/unittests/ADT/BitVectorTest.cpp b/llvm/unittests/ADT/BitVectorTest.cpp
index e00e11e4655aa..79d5dee5ad30f 100644
--- a/llvm/unittests/ADT/BitVectorTest.cpp
+++ b/llvm/unittests/ADT/BitVectorTest.cpp
@@ -1143,6 +1143,9 @@ TYPED_TEST(BitVectorTest, EmptyVectorGetData) {
}
TYPED_TEST(BitVectorTest, Iterators) {
+ TypeParam Singleton(1);
+ EXPECT_EQ(std::next(Singleton.set_bits_begin()), Singleton.set_bits_end());
+
TypeParam Filled(10, true);
EXPECT_NE(Filled.set_bits_begin(), Filled.set_bits_end());
unsigned Counter = 0;
More information about the llvm-commits
mailing list