Skip to content

Commit 915e176

Browse files
committed
Temporarily fix vector<bool>::operator==
1 parent 2f695b1 commit 915e176

File tree

6 files changed

+22
-68
lines changed

6 files changed

+22
-68
lines changed

libcxx/include/__algorithm/equal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
#include <__type_traits/is_volatile.h>
2929
#include <__utility/move.h>
3030

31-
#if _LIBCPP_STD_VER >= 20
32-
# include <__functional/ranges_operations.h>
33-
#endif
34-
3531
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3632
# pragma GCC system_header
3733
#endif

libcxx/include/__vector/comparison.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __
2929
return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
3030
}
3131

32+
// FIXME: Remove this `vector<bool>` overload once #126369 is resolved, reverting to the generic `operator==`
33+
// with `std::equal` for better performance.
34+
template <class _Allocator>
35+
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
36+
operator==(const vector<bool, _Allocator>& __x, const vector<bool, _Allocator>& __y) {
37+
const typename vector<bool, _Allocator>::size_type __sz = __x.size();
38+
if (__sz != __y.size())
39+
return false;
40+
for (typename vector<bool, _Allocator>::size_type __i = 0; __i < __sz; ++__i)
41+
if (__x[__i] != __y[__i])
42+
return false;
43+
return true;
44+
}
45+
3246
#if _LIBCPP_STD_VER <= 17
3347

3448
template <class _Tp, class _Allocator>

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,14 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
5656
std::vector<bool, Alloc> in(100, false, Alloc(1));
5757
std::vector<bool, Alloc> expected(100, true, Alloc(1));
5858
std::fill(in.begin(), in.end(), true);
59-
60-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
61-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
62-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
63-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
64-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
65-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
66-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
59+
assert(in == expected);
6760
}
6861
{
6962
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
7063
std::vector<bool, Alloc> in(200, false, Alloc(1));
7164
std::vector<bool, Alloc> expected(200, true, Alloc(1));
7265
std::fill(in.begin(), in.end(), true);
73-
74-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
75-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
76-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
77-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
78-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
79-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
80-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
66+
assert(in == expected);
8167
}
8268
{
8369
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,14 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
117117
std::vector<bool, Alloc> in(100, false, Alloc(1));
118118
std::vector<bool, Alloc> expected(100, true, Alloc(1));
119119
std::fill_n(in.begin(), in.size(), true);
120-
121-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
122-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
123-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
124-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
125-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
126-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
127-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
120+
assert(in == expected);
128121
}
129122
{
130123
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
131124
std::vector<bool, Alloc> in(200, false, Alloc(1));
132125
std::vector<bool, Alloc> expected(200, true, Alloc(1));
133126
std::fill_n(in.begin(), in.size(), true);
134-
135-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
136-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
137-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
138-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
139-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
140-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
141-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
127+
assert(in == expected);
142128
}
143129
{
144130
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/ranges.fill.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,14 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
9191
std::vector<bool, Alloc> in(100, false, Alloc(1));
9292
std::vector<bool, Alloc> expected(100, true, Alloc(1));
9393
std::ranges::fill(in, true);
94-
95-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
96-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
97-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
98-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
99-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
100-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
101-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
94+
assert(in == expected);
10295
}
10396
{
10497
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
10598
std::vector<bool, Alloc> in(200, false, Alloc(1));
10699
std::vector<bool, Alloc> expected(200, true, Alloc(1));
107100
std::ranges::fill(in, true);
108-
109-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
110-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
111-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
112-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
113-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
114-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
115-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
101+
assert(in == expected);
116102
}
117103
{
118104
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;

libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/ranges.fill_n.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,14 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() {
6464
std::vector<bool, Alloc> in(100, false, Alloc(1));
6565
std::vector<bool, Alloc> expected(100, true, Alloc(1));
6666
std::ranges::fill_n(std::ranges::begin(in), in.size(), true);
67-
68-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
69-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
70-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
71-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
72-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
73-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
74-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
67+
assert(in == expected);
7568
}
7669
{
7770
using Alloc = sized_allocator<bool, std::uint16_t, std::int16_t>;
7871
std::vector<bool, Alloc> in(200, false, Alloc(1));
7972
std::vector<bool, Alloc> expected(200, true, Alloc(1));
8073
std::ranges::fill_n(std::ranges::begin(in), in.size(), true);
81-
82-
// FIXME: We are currently forced to use the standard `std::equal()` for general `input_iterator`s instead of
83-
// the optimized version for `__bit_iterator`s. This is due to a recently discovered issue #126369 where the
84-
// optimization fails to correctly compare `vector<bool>`s with small integral storage types. Once the issue is
85-
// fixed, we should revert to the optimized version by uncommenting the last line in this code block.
86-
using It = cpp17_input_iterator<std::vector<bool, Alloc>::iterator>;
87-
assert(in.size() == expected.size() && std::equal(It(in.begin()), It(in.end()), It(expected.begin())));
88-
// assert(in == expected); // FIXME: Uncomment this line once issue #126369 is fixed.
74+
assert(in == expected);
8975
}
9076
{
9177
using Alloc = sized_allocator<bool, std::uint32_t, std::int32_t>;

0 commit comments

Comments
 (0)