@@ -48,89 +48,96 @@ struct Test {
48
48
}
49
49
};
50
50
51
- // Make sure std::fill behaves properly with std::vector<bool> iterators with custom size types.
52
- // See https://github.com/llvm/llvm-project/pull/122410.
53
- TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types () {
54
- {
55
- using Alloc = sized_allocator< bool , std::uint8_t , std:: int8_t > ;
56
- std::vector< bool , Alloc> in ( 100 , false , Alloc ( 1 )) ;
57
- std::vector< bool , Alloc> expected ( 100 , true , Alloc ( 1 ) );
58
- std::fill (in. begin (), in. end (), true );
59
- assert (in == expected);
60
- }
61
- {
62
- using Alloc = sized_allocator< bool , std::uint16_t , std:: int16_t > ;
63
- std::vector< bool , Alloc> in ( 200 , false , Alloc ( 1 )) ;
64
- std::vector< bool , Alloc> expected ( 200 , true , Alloc ( 1 ) );
65
- std::fill (in. begin (), in. end (), true );
66
- assert (in == expected);
67
- }
68
- {
69
- using Alloc = sized_allocator< bool , std::uint32_t , std:: int32_t > ;
70
- std::vector< bool , Alloc> in ( 200 , false , Alloc ( 1 )) ;
71
- std::vector< bool , Alloc> expected ( 200 , true , Alloc ( 1 ) );
72
- std::fill (in. begin (), in. end (), true );
73
- assert (in == expected);
51
+ TEST_CONSTEXPR_CXX20 bool test_vector_bool ( std::size_t N) {
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
+ }
74
74
}
75
- {
76
- using Alloc = sized_allocator<bool , std::uint64_t , std::int64_t >;
77
- std::vector<bool , Alloc> in (200 , false , Alloc (1 ));
78
- std::vector<bool , Alloc> expected (200 , true , Alloc (1 ));
79
- std::fill (in.begin (), in.end (), true );
80
- assert (in == expected);
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
+ }
81
91
}
92
+
93
+ return true ;
82
94
}
83
95
84
96
TEST_CONSTEXPR_CXX20 bool test () {
85
97
types::for_each (types::forward_iterator_list<char *>(), Test<char >());
86
98
types::for_each (types::forward_iterator_list<int *>(), Test<int >());
87
- { // test vector<bool>::iterator optimization
88
- { // simple case
89
- std::vector<bool > in (4 , false );
90
- std::vector<bool > expected (4 , true );
99
+
100
+ { // Test vector<bool>::iterator optimization
101
+ assert (test_vector_bool (8 ));
102
+ assert (test_vector_bool (19 ));
103
+ assert (test_vector_bool (32 ));
104
+ assert (test_vector_bool (49 ));
105
+ assert (test_vector_bool (64 ));
106
+ assert (test_vector_bool (199 ));
107
+ assert (test_vector_bool (256 ));
108
+
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 ));
91
115
std::fill (in.begin (), in.end (), true );
92
116
assert (in == expected);
93
117
}
94
- { // partial byte in the front is not filled
95
- std::vector<bool > in (8 , false );
96
- std::vector<bool > expected (8 , true );
97
- expected[0 ] = false ;
98
- expected[1 ] = false ;
99
- std::fill (in.begin () + 2 , in.end (), true );
100
- assert (in == expected);
101
- }
102
- { // partial byte in the back is not filled
103
- std::vector<bool > in (8 , false );
104
- std::vector<bool > expected (8 , true );
105
- expected[6 ] = false ;
106
- expected[7 ] = false ;
107
- std::fill (in.begin (), in.end () - 2 , true );
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 );
108
123
assert (in == expected);
109
124
}
110
- { // partial byte in the front and back is not filled
111
- std::vector<bool > in (16 , false );
112
- std::vector<bool > expected (16 , true );
113
- expected[0 ] = false ;
114
- expected[1 ] = false ;
115
- expected[14 ] = false ;
116
- expected[15 ] = false ;
117
- std::fill (in.begin () + 2 , in.end () - 2 , true );
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 );
118
130
assert (in == expected);
119
131
}
120
- { // only a few bits of a byte are set
121
- std::vector<bool > in (8 , false );
122
- std::vector<bool > expected (8 , true );
123
- expected[0 ] = false ;
124
- expected[1 ] = false ;
125
- expected[6 ] = false ;
126
- expected[7 ] = false ;
127
- std::fill (in.begin () + 2 , in.end () - 2 , true );
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 );
128
137
assert (in == expected);
129
138
}
130
139
}
131
140
132
- test_bititer_with_custom_sized_types ();
133
-
134
141
return true ;
135
142
}
136
143
0 commit comments