[llvm] [ADT] Allow std::next to work on BitVector's set_bits_iterator (PR #80830)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 05:09:53 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
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
^
---
Full diff: https://github.com/llvm/llvm-project/pull/80830.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/BitVector.h (+1-1)
- (modified) llvm/unittests/ADT/BitVectorTest.cpp (+3)
``````````diff
diff --git a/llvm/include/llvm/ADT/BitVector.h b/llvm/include/llvm/ADT/BitVector.h
index e0de1afcc94182..0eaa77b6dd81ce 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 e00e11e4655aa0..79d5dee5ad30fd 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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/80830
More information about the llvm-commits
mailing list