@@ -67,7 +67,7 @@ struct NonAggregate {
67
67
TEST (Array, WithDefault) {
68
68
auto a = Array<int , 5 >::with_default ();
69
69
static_assert (sizeof (a) == sizeof (int [5 ]));
70
- for (size_t i = 0 ; i < 5 ; ++i ) {
70
+ for (auto i = 0_usize ; i < 5_usize; i += 1_usize ) {
71
71
EXPECT_EQ (a.get (i), 0 );
72
72
}
73
73
@@ -87,62 +87,62 @@ TEST(Array, WithUninitialized) {
87
87
}
88
88
89
89
TEST (Array, WithInitializer) {
90
- auto a = Array<int , 5 >::with_initializer ([i = 1 ]() mutable { return i++; });
91
- static_assert (sizeof (a) == sizeof (int [5 ]));
92
- for (size_t i = 0 ; i < 5 ; ++i) {
93
- EXPECT_EQ (a.get (i), i + 1 );
90
+ auto a =
91
+ Array<usize, 5 >::with_initializer ([i = 1u ]() mutable { return i++; });
92
+ static_assert (sizeof (a) == sizeof (usize[5 ]));
93
+ for (auto i = 0_usize; i < 5_usize; i += 1_usize) {
94
+ EXPECT_EQ (a.get (i), i + 1_usize);
94
95
}
95
96
96
97
struct NotTriviallyDefaultConstructible {
97
98
NotTriviallyDefaultConstructible () {}
98
- NotTriviallyDefaultConstructible (int i) : i(i) {}
99
- int i;
99
+ NotTriviallyDefaultConstructible (usize i) : i(i) {}
100
+ usize i;
100
101
};
101
102
static_assert (!std::is_trivially_default_constructible_v<
102
103
NotTriviallyDefaultConstructible>,
103
104
" " );
104
105
auto b = Array<NotTriviallyDefaultConstructible, 5 >::with_initializer (
105
- [i = 1 ]() mutable -> NotTriviallyDefaultConstructible { return {i++}; });
106
+ [i = 1u ]() mutable -> NotTriviallyDefaultConstructible { return {i++}; });
106
107
static_assert (sizeof (b) == sizeof (NotTriviallyDefaultConstructible[5 ]));
107
- for (size_t i = 0 ; i < 5 ; ++i ) {
108
- EXPECT_EQ (b.get (i).i , i + 1 );
108
+ for (auto i = 0_usize ; i < 5_usize; i += 1_usize ) {
109
+ EXPECT_EQ (b.get (i).i , i + 1_usize );
109
110
}
110
111
111
- auto lvalue = [i = 1 ]() mutable { return i++; };
112
- auto c = Array<int , 5 >::with_initializer (lvalue);
113
- static_assert (sizeof (c) == sizeof (int [5 ]));
114
- for (size_t i = 0 ; i < 5 ; ++i ) {
115
- EXPECT_EQ (c.get (i), i + 1 );
112
+ auto lvalue = [i = 1u ]() mutable { return i++; };
113
+ auto c = Array<usize , 5 >::with_initializer (lvalue);
114
+ static_assert (sizeof (c) == sizeof (usize [5 ]));
115
+ for (auto i = 0_usize ; i < 5_usize; i += 1_usize ) {
116
+ EXPECT_EQ (c.get (i), i + 1_usize );
116
117
}
117
118
118
- static_assert (sizeof (Array<int , 5 >::with_initializer ([]() { return 1 ; })) ==
119
- sizeof (int [5 ]),
119
+ static_assert (sizeof (Array<usize , 5 >::with_initializer (
120
+ []() { return 1u ; })) == sizeof (usize [5 ]),
120
121
" " );
121
122
}
122
123
123
124
TEST (Array, WithValue) {
124
- auto a = Array<int , 5 >::with_value (3 );
125
- static_assert (sizeof (a) == sizeof (int [5 ]));
126
- for (size_t i = 0 ; i < 5 ; ++i ) {
127
- EXPECT_EQ (a.get (i), 3 );
125
+ auto a = Array<usize , 5 >::with_value (3u );
126
+ static_assert (sizeof (a) == sizeof (usize [5 ]));
127
+ for (auto i = 0_usize ; i < 5_usize; i += 1_usize ) {
128
+ EXPECT_EQ (a.get (i), 3_usize );
128
129
}
129
130
}
130
131
131
132
TEST (Array, WithValues) {
132
133
{
133
- auto a = Array<int , 5 >::with_values (3 , 4 , 5 , 6 , 7 );
134
- static_assert (sizeof (a) == sizeof (int [5 ]));
135
- for (size_t i = 0 ; i < 5 ; ++i ) {
136
- EXPECT_EQ (a.get (i), 3 + i);
134
+ auto a = Array<usize , 5 >::with_values (3u , 4u , 5u , 6u , 7u );
135
+ static_assert (sizeof (a) == sizeof (usize [5 ]));
136
+ for (auto i = 0_usize ; i < 5_usize; i += 1_usize ) {
137
+ EXPECT_EQ (a.get (i), 3_usize + i);
137
138
}
138
139
}
139
140
{
140
141
auto a = Array<u8 , 5 >::with_values (sus::into (3 ), sus::into (4 ), sus::into (5 ),
141
142
sus::into (6 ), sus::into (7 ));
142
143
static_assert (sizeof (a) == sizeof (u8 [5 ]));
143
144
for (auto i = 0_u8; i < 5_u8; i += 1_u8) {
144
- EXPECT_EQ (a.get (/* TODO: usize */ usize::from (i).primitive_value ),
145
- 3_u8 + i);
145
+ EXPECT_EQ (a.get (usize::from (i)), 3_u8 + i);
146
146
}
147
147
}
148
148
}
@@ -152,15 +152,15 @@ TEST(Array, Get) {
152
152
constexpr auto r = []() constexpr {
153
153
constexpr auto a =
154
154
Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
155
- return a.get (2 );
155
+ return a.get (2_usize );
156
156
}
157
157
();
158
158
static_assert (std::same_as<decltype (r), const int >);
159
159
EXPECT_EQ (3 , r);
160
160
}
161
161
{
162
162
auto a = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
163
- EXPECT_EQ (3 , a.get (2 ));
163
+ EXPECT_EQ (3 , a.get (2_usize ));
164
164
}
165
165
}
166
166
@@ -169,16 +169,16 @@ TEST(Array, GetMut) {
169
169
constexpr auto a = []() constexpr {
170
170
auto a =
171
171
Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
172
- a.get_mut (0 ) = 101 ;
172
+ a.get_mut (0_usize ) = 101 ;
173
173
return a;
174
174
}
175
175
();
176
- EXPECT_EQ (a.get (0 ), 101 );
176
+ EXPECT_EQ (a.get (0_usize ), 101 );
177
177
}
178
178
{
179
179
auto a = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
180
- a.get_mut (0 ) = 101 ;
181
- EXPECT_EQ (a.get (0 ), 101 );
180
+ a.get_mut (0_usize ) = 101 ;
181
+ EXPECT_EQ (a.get (0_usize ), 101 );
182
182
}
183
183
}
184
184
@@ -201,7 +201,7 @@ TEST(Array, Eq) {
201
201
auto a = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
202
202
auto b = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
203
203
EXPECT_EQ (a, b);
204
- b.get_mut (3 ) += 1 ;
204
+ b.get_mut (3_usize ) += 1 ;
205
205
EXPECT_NE (a, b);
206
206
}
207
207
@@ -210,15 +210,15 @@ TEST(Array, Ord) {
210
210
auto b = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
211
211
EXPECT_LE (a, b);
212
212
EXPECT_GE (a, b);
213
- b.get_mut (3 ) += 1 ;
213
+ b.get_mut (3_usize ) += 1 ;
214
214
EXPECT_LT (a, b);
215
215
}
216
216
217
217
TEST (Array, StrongOrder) {
218
218
auto a = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
219
219
auto b = Array<int , 5 >::with_initializer ([i = 0 ]() mutable { return ++i; });
220
220
EXPECT_EQ (std::strong_order (a, b), std::strong_ordering::equal);
221
- b.get_mut (3 ) += 1 ;
221
+ b.get_mut (3_usize ) += 1 ;
222
222
EXPECT_EQ (std::strong_order (a, b), std::strong_ordering::less);
223
223
}
224
224
@@ -236,18 +236,22 @@ struct Weak final {
236
236
};
237
237
238
238
TEST (Array, WeakOrder) {
239
- auto a = Array<Weak, 5 >::with_initializer ([i = 0 ]() mutable { return Weak (++i, 2 ); });
240
- auto b = Array<Weak, 5 >::with_initializer ([i = 0 ]() mutable { return Weak (++i, 2 ); });
239
+ auto a = Array<Weak, 5 >::with_initializer (
240
+ [i = 0 ]() mutable { return Weak (++i, 2 ); });
241
+ auto b = Array<Weak, 5 >::with_initializer (
242
+ [i = 0 ]() mutable { return Weak (++i, 2 ); });
241
243
EXPECT_EQ (std::weak_order (a, b), std::weak_ordering::equivalent);
242
- b.get_mut (3 ).a += 1 ;
244
+ b.get_mut (3_usize ).a += 1 ;
243
245
EXPECT_EQ (std::weak_order (a, b), std::weak_ordering::less);
244
246
}
245
247
246
248
TEST (Array, PartialOrder) {
247
- auto a = Array<float , 5 >::with_initializer ([i = 0 .f ]() mutable { return ++i; });
248
- auto b = Array<float , 5 >::with_initializer ([i = 0 .f ]() mutable { return ++i; });
249
+ auto a =
250
+ Array<float , 5 >::with_initializer ([i = 0 .f ]() mutable { return ++i; });
251
+ auto b =
252
+ Array<float , 5 >::with_initializer ([i = 0 .f ]() mutable { return ++i; });
249
253
EXPECT_EQ (std::partial_order (a, b), std::partial_ordering::equivalent);
250
- b.get_mut (3 ) += 1 ;
254
+ b.get_mut (3_usize ) += 1 ;
251
255
EXPECT_EQ (std::partial_order (a, b), std::partial_ordering::less);
252
256
}
253
257
0 commit comments