[libcxx-commits] [libcxx] [libc++] Optimize ranges::equal for vector<bool>::iterator (PR #121084)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 20 13:15:07 PST 2025


================
@@ -55,14 +55,28 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
     std::vector<bool, Alloc> in(100, false, Alloc(1));
     std::vector<bool, Alloc> expected(100, true, Alloc(1));
     std::fill(in.begin(), in.end(), true);
-    assert(in == expected);
+
+    // FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
+    // the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
+    // optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
+    // fixed, we should revert to the optimized version by uncommenting the last line in this code block.
+    using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
+    assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
+    // assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
----------------
winner245 wrote:

Thank you very much for catching this! I agree that preserving the functionality of `operator==` is the priority here. I’ve added a slow but correct implementation for `vector<bool>::operator==` as you suggested. Since I've introduced a separate overload for `vector<bool>::operator==` instead of modifying the generic `vector<_Tp, _Allocator>::operator==`, we can simply remove it once #126369 is resolved. I’ve also added a FIXME comment to note this. 

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


More information about the libcxx-commits mailing list