@@ -49,55 +49,50 @@ struct Test {
49
49
};
50
50
51
51
TEST_CONSTEXPR_CXX20 bool test_vector_bool (std::size_t N) {
52
- { // Test with full bytes
53
- std::vector<bool > in (N, false );
54
- std::vector<bool > expected (N, true );
55
- std::fill (in.begin (), in.end (), true );
56
- assert (in == expected);
52
+ { // Test cases validating leading/trailing bits unfilled remain unchanged
53
+ { // Leading bits are not filled
54
+ std::vector<bool > in (N, false );
55
+ std::vector<bool > expected (N, true );
56
+ expected[0 ] = expected[1 ] = false ;
57
+ std::fill (in.begin () + 2 , in.end (), true );
58
+ assert (in == expected);
59
+ }
60
+ { // Trailing bits are not filled
61
+ std::vector<bool > in (N, false );
62
+ std::vector<bool > expected (N, true );
63
+ expected[N - 1 ] = expected[N - 2 ] = false ;
64
+ std::fill (in.begin (), in.end () - 2 , true );
65
+ assert (in == expected);
66
+ }
67
+ { // Leading and trailing bits are not filled
68
+ std::vector<bool > in (N, false );
69
+ std::vector<bool > expected (N, true );
70
+ expected[0 ] = expected[1 ] = expected[N - 1 ] = expected[N - 2 ] = false ;
71
+ std::fill (in.begin () + 2 , in.end () - 2 , true );
72
+ assert (in == expected);
73
+ }
57
74
}
58
- { // Test with partial bytes with offset
59
- std::vector<bool > in (N, false );
60
- std::vector<bool > expected (N, true );
61
- std::fill (in.begin () + 4 , in.end () - 4 , true );
62
- assert (std::equal (in.begin () + 4 , in.end () - 4 , expected.begin ()));
75
+
76
+ { // Test cases with full or partial bytes filled
77
+ { // Full bytes filled
78
+ std::vector<bool > in (N, false );
79
+ std::vector<bool > expected (N, true );
80
+ std::fill (in.begin (), in.end (), true );
81
+ assert (in == expected);
82
+ }
83
+ { // Partial bytes with offset filled
84
+ std::vector<bool > in (N, false );
85
+ std::vector<bool > expected (N, true );
86
+ std::fill (in.begin () + 4 , in.end () - 4 , true );
87
+ std::fill (expected.begin (), expected.begin () + 4 , false );
88
+ std::fill (expected.end () - 4 , expected.end (), false );
89
+ assert (in == expected);
90
+ }
63
91
}
64
92
65
93
return true ;
66
94
}
67
95
68
- // Make sure std::fill behaves properly with std::vector<bool> iterators with custom size types.
69
- // See https://github.com/llvm/llvm-project/pull/122410.
70
- TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types () {
71
- {
72
- using Alloc = sized_allocator<bool , std::uint8_t , std::int8_t >;
73
- std::vector<bool , Alloc> in (100 , false , Alloc (1 ));
74
- std::vector<bool , Alloc> expected (100 , true , Alloc (1 ));
75
- std::fill (in.begin (), in.end (), true );
76
- assert (in == expected);
77
- }
78
- {
79
- using Alloc = sized_allocator<bool , std::uint16_t , std::int16_t >;
80
- std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
81
- std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
82
- std::fill (in.begin (), in.end (), true );
83
- assert (in == expected);
84
- }
85
- {
86
- using Alloc = sized_allocator<bool , std::uint32_t , std::int32_t >;
87
- std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
88
- std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
89
- std::fill (in.begin (), in.end (), true );
90
- assert (in == expected);
91
- }
92
- {
93
- using Alloc = sized_allocator<bool , std::uint64_t , std::int64_t >;
94
- std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
95
- std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
96
- std::fill (in.begin (), in.end (), true );
97
- assert (in == expected);
98
- }
99
- }
100
-
101
96
TEST_CONSTEXPR_CXX20 bool test () {
102
97
types::for_each (types::forward_iterator_list<char *>(), Test<char >());
103
98
types::for_each (types::forward_iterator_list<int *>(), Test<int >());
@@ -110,9 +105,38 @@ TEST_CONSTEXPR_CXX20 bool test() {
110
105
assert (test_vector_bool (64 ));
111
106
assert (test_vector_bool (199 ));
112
107
assert (test_vector_bool (256 ));
113
- }
114
108
115
- test_bititer_with_custom_sized_types ();
109
+ // Make sure std::fill behaves properly with std::vector<bool> iterators with custom size types.
110
+ // See https://github.com/llvm/llvm-project/pull/122410.
111
+ {
112
+ using Alloc = sized_allocator<bool , std::uint8_t , std::int8_t >;
113
+ std::vector<bool , Alloc> in (100 , false , Alloc (1 ));
114
+ std::vector<bool , Alloc> expected (100 , true , Alloc (1 ));
115
+ std::fill (in.begin (), in.end (), true );
116
+ assert (in == expected);
117
+ }
118
+ {
119
+ using Alloc = sized_allocator<bool , std::uint16_t , std::int16_t >;
120
+ std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
121
+ std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
122
+ std::fill (in.begin (), in.end (), true );
123
+ assert (in == expected);
124
+ }
125
+ {
126
+ using Alloc = sized_allocator<bool , std::uint32_t , std::int32_t >;
127
+ std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
128
+ std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
129
+ std::fill (in.begin (), in.end (), true );
130
+ assert (in == expected);
131
+ }
132
+ {
133
+ using Alloc = sized_allocator<bool , std::uint64_t , std::int64_t >;
134
+ std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
135
+ std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
136
+ std::fill (in.begin (), in.end (), true );
137
+ assert (in == expected);
138
+ }
139
+ }
116
140
117
141
return true ;
118
142
}
0 commit comments