Skip to content

Commit d59fc21

Browse files
committed
Replace built-in array by std::array in the test
1 parent 57101ac commit d59fc21

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

libcxx/test/benchmarks/containers/ContainerBenchmarks.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void BM_CopyConstruct_Alloc(benchmark::State& st, Container, Allocator a) {
4444
auto size = st.range(0);
4545
Container c(size);
4646
for (auto _ : st) {
47-
Container v(c, a);
47+
Container v(c, a); // we assume the destructor doesn't dominate the benchmark
4848
DoNotOptimizeData(v);
4949
}
5050
}

libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// vector(const vector& v);
1313

14+
#include <array>
1415
#include <cassert>
1516
#include <memory>
1617
#include <vector>
@@ -31,46 +32,46 @@ TEST_CONSTEXPR_CXX20 void test(const std::vector<bool, A>& x) {
3132
}
3233

3334
TEST_CONSTEXPR_CXX20 bool tests() {
34-
bool a05[5] = {1, 0, 1, 0, 1};
35-
bool a17[17] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1};
36-
bool a33[33] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1};
37-
bool a65[65] = {0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
35+
std::array<int, 5> a1 = {1, 0, 1, 0, 1};
36+
std::array<int, 17> a2 = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1};
37+
std::array<int, 33> a3 = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1};
38+
std::array<int, 65> a4 = {0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
3839

3940
{ // Test the copy constructor with the default allocator
40-
test(std::vector<bool>(a05, a05 + sizeof(a05) / sizeof(a05[0])));
41-
test(std::vector<bool>(a17, a17 + sizeof(a17) / sizeof(a17[0])));
42-
test(std::vector<bool>(a33, a33 + sizeof(a33) / sizeof(a33[0])));
43-
test(std::vector<bool>(a65, a65 + sizeof(a65) / sizeof(a65[0])));
41+
test(std::vector<bool>(a1.begin(), a1.end()));
42+
test(std::vector<bool>(a2.begin(), a2.end()));
43+
test(std::vector<bool>(a3.begin(), a3.end()));
44+
test(std::vector<bool>(a4.begin(), a4.end()));
4445
test(std::vector<bool>(257, true));
4546
}
4647

4748
{ // Test the copy constructor with test_allocator
4849
using A = test_allocator<bool>;
4950
using C = std::vector<bool, A>;
50-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A(5)));
51-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A(5)));
52-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A(5)));
53-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A(5)));
51+
test(C(a1.begin(), a1.end()));
52+
test(C(a2.begin(), a2.end()));
53+
test(C(a3.begin(), a3.end()));
54+
test(C(a4.begin(), a4.end()));
5455
test(C(257, true, A(5)));
5556
}
5657

5758
{ // Test the copy constructor with other_allocator
5859
using A = other_allocator<bool>;
5960
using C = std::vector<bool, A>;
60-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A(5)));
61-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A(5)));
62-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A(5)));
63-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A(5)));
61+
test(C(a1.begin(), a1.end()));
62+
test(C(a2.begin(), a2.end()));
63+
test(C(a3.begin(), a3.end()));
64+
test(C(a4.begin(), a4.end()));
6465
test(C(257, true, A(5)));
6566
}
6667

6768
{ // Test the copy constructor with min_allocator
6869
using A = min_allocator<bool>;
6970
using C = std::vector<bool, A>;
70-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A()));
71-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A()));
72-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A()));
73-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A()));
71+
test(C(a1.begin(), a1.end()));
72+
test(C(a2.begin(), a2.end()));
73+
test(C(a3.begin(), a3.end()));
74+
test(C(a4.begin(), a4.end()));
7475
test(C(257, true, A()));
7576
}
7677

libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// vector(const vector& v, const allocator_type& a);
1313

14+
#include <array>
1415
#include <cassert>
1516
#include <vector>
1617

@@ -28,46 +29,46 @@ TEST_CONSTEXPR_CXX20 void test(const std::vector<bool, A>& x, const A& a) {
2829
}
2930

3031
TEST_CONSTEXPR_CXX20 bool tests() {
31-
bool a05[5] = {1, 0, 1, 0, 1};
32-
bool a17[17] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1};
33-
bool a33[33] = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1};
34-
bool a65[65] = {0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
32+
std::array<int, 5> a1 = {1, 0, 1, 0, 1};
33+
std::array<int, 17> a2 = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1};
34+
std::array<int, 33> a3 = {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1};
35+
std::array<int, 65> a4 = {0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0};
3536

3637
{ // Test with the default allocator
37-
test(std::vector<bool>(a05, a05 + sizeof(a05) / sizeof(a05[0])), std::allocator<bool>());
38-
test(std::vector<bool>(a17, a17 + sizeof(a17) / sizeof(a17[0])), std::allocator<bool>());
39-
test(std::vector<bool>(a33, a33 + sizeof(a33) / sizeof(a33[0])), std::allocator<bool>());
40-
test(std::vector<bool>(a65, a65 + sizeof(a65) / sizeof(a65[0])), std::allocator<bool>());
38+
test(std::vector<bool>(a1.begin(), a1.end()), std::allocator<bool>());
39+
test(std::vector<bool>(a2.begin(), a2.end()), std::allocator<bool>());
40+
test(std::vector<bool>(a3.begin(), a3.end()), std::allocator<bool>());
41+
test(std::vector<bool>(a4.begin(), a4.end()), std::allocator<bool>());
4142
test(std::vector<bool>(257, true), std::allocator<bool>());
4243
}
4344

4445
{ // Test with test_allocator
4546
using A = test_allocator<bool>;
4647
using C = std::vector<bool, A>;
47-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A(5)), A(3));
48-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A(5)), A(3));
49-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A(5)), A(3));
50-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A(5)), A(3));
48+
test(C(a1.begin(), a1.end(), A(5)), A(3));
49+
test(C(a2.begin(), a2.end(), A(5)), A(3));
50+
test(C(a3.begin(), a3.end(), A(5)), A(3));
51+
test(C(a4.begin(), a4.end(), A(5)), A(3));
5152
test(C(257, true, A(5)), A(3));
5253
}
5354

5455
{ // Test with other_allocator
5556
using A = other_allocator<bool>;
5657
using C = std::vector<bool, A>;
57-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A(5)), A(3));
58-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A(5)), A(3));
59-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A(5)), A(3));
60-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A(5)), A(3));
58+
test(C(a1.begin(), a1.end(), A(5)), A(3));
59+
test(C(a2.begin(), a2.end(), A(5)), A(3));
60+
test(C(a3.begin(), a3.end(), A(5)), A(3));
61+
test(C(a4.begin(), a4.end(), A(5)), A(3));
6162
test(C(257, true, A(5)), A(3));
6263
}
6364

6465
{ // Test with min_allocator
6566
using A = min_allocator<bool>;
6667
using C = std::vector<bool, A>;
67-
test(C(a05, a05 + sizeof(a05) / sizeof(a05[0]), A()), A());
68-
test(C(a17, a17 + sizeof(a17) / sizeof(a17[0]), A()), A());
69-
test(C(a33, a33 + sizeof(a33) / sizeof(a33[0]), A()), A());
70-
test(C(a65, a65 + sizeof(a65) / sizeof(a65[0]), A()), A());
68+
test(C(a1.begin(), a1.end(), A()), A());
69+
test(C(a2.begin(), a2.end(), A()), A());
70+
test(C(a3.begin(), a3.end(), A()), A());
71+
test(C(a4.begin(), a4.end(), A()), A());
7172
test(C(257, true, A()), A());
7273
}
7374

0 commit comments

Comments
 (0)