7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
// <vector>
10
+ // vector<bool>
10
11
11
12
// vector(const vector& v, const allocator_type& a);
12
13
13
- #include < vector >
14
+ #include < array >
14
15
#include < cassert>
16
+ #include < vector>
15
17
16
- #include " test_macros.h"
17
- #include " test_allocator.h"
18
18
#include " min_allocator.h"
19
+ #include " test_allocator.h"
20
+ #include " test_macros.h"
19
21
20
22
template <class C >
21
23
TEST_CONSTEXPR_CXX20 void test (const C& x, const typename C::allocator_type& a) {
@@ -24,39 +26,53 @@ TEST_CONSTEXPR_CXX20 void test(const C& x, const typename C::allocator_type& a)
24
26
LIBCPP_ASSERT (c.__invariants ());
25
27
assert (c.size () == s);
26
28
assert (c == x);
29
+ assert (c.get_allocator () == a);
27
30
}
28
31
29
32
TEST_CONSTEXPR_CXX20 bool tests () {
30
- {
31
- bool a[] = {0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 };
32
- bool * an = a + sizeof (a) / sizeof (a[0 ]);
33
- test (std::vector<bool >(a, an), std::allocator<bool >());
34
- }
35
- {
36
- std::vector<bool , test_allocator<bool > > l (3 , true , test_allocator<bool >(5 ));
37
- std::vector<bool , test_allocator<bool > > l2 (l, test_allocator<bool >(3 ));
38
- assert (l2 == l);
39
- assert (l2.get_allocator () == test_allocator<bool >(3 ));
33
+ std::array<int , 5 > a1 = {1 , 0 , 1 , 0 , 1 };
34
+ std::array<int , 18 > a2 = {0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 };
35
+ std::array<int , 33 > a3 = {0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 };
36
+ std::array<int , 65 > a4 = {0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 };
37
+ std::array<int , 299 > a5 = {};
38
+ for (unsigned i = 0 ; i < a5.size (); i += 2 )
39
+ a5[i] = 1 ;
40
+
41
+ // Tests for allocator-extended copy constructor with word size up to 5 (i.e., bit size > 256 on a 64-bit system)
42
+ { // Test with the default std::allocator
43
+ test (std::vector<bool >(a1.begin (), a1.end ()), std::allocator<bool >());
44
+ test (std::vector<bool >(a2.begin (), a2.end ()), std::allocator<bool >());
45
+ test (std::vector<bool >(a3.begin (), a3.end ()), std::allocator<bool >());
46
+ test (std::vector<bool >(a4.begin (), a4.end ()), std::allocator<bool >());
47
+ test (std::vector<bool >(a5.begin (), a5.end ()), std::allocator<bool >());
40
48
}
41
- {
42
- std::vector<bool , other_allocator<bool > > l (3 , true , other_allocator<bool >(5 ));
43
- std::vector<bool , other_allocator<bool > > l2 (l, other_allocator<bool >(3 ));
44
- assert (l2 == l);
45
- assert (l2.get_allocator () == other_allocator<bool >(3 ));
49
+ { // Test with test_allocator
50
+ using A = test_allocator<bool >;
51
+ using C = std::vector<bool , A>;
52
+ test (C (a1.begin (), a1.end (), A (5 )), A (3 ));
53
+ test (C (a2.begin (), a2.end (), A (5 )), A (3 ));
54
+ test (C (a3.begin (), a3.end (), A (5 )), A (3 ));
55
+ test (C (a4.begin (), a4.end (), A (5 )), A (3 ));
56
+ test (C (a5.begin (), a5.end (), A (5 )), A (3 ));
46
57
}
47
- #if TEST_STD_VER >= 11
48
- {
49
- bool a[] = {0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 1 , 0 };
50
- bool * an = a + sizeof (a) / sizeof (a[0 ]);
51
- test (std::vector<bool , min_allocator<bool >>(a, an), min_allocator<bool >());
58
+ { // Test with other_allocator
59
+ using A = other_allocator<bool >;
60
+ using C = std::vector<bool , A>;
61
+ test (C (a1.begin (), a1.end (), A (5 )), A (3 ));
62
+ test (C (a2.begin (), a2.end (), A (5 )), A (3 ));
63
+ test (C (a3.begin (), a3.end (), A (5 )), A (3 ));
64
+ test (C (a4.begin (), a4.end (), A (5 )), A (3 ));
65
+ test (C (a5.begin (), a5.end (), A (5 )), A (3 ));
52
66
}
53
- {
54
- std::vector<bool , min_allocator<bool > > l (3 , true , min_allocator<bool >());
55
- std::vector<bool , min_allocator<bool > > l2 (l, min_allocator<bool >());
56
- assert (l2 == l);
57
- assert (l2.get_allocator () == min_allocator<bool >());
67
+ { // Test with min_allocator
68
+ using A = min_allocator<bool >;
69
+ using C = std::vector<bool , A>;
70
+ test (C (a1.begin (), a1.end (), A ()), A ());
71
+ test (C (a2.begin (), a2.end (), A ()), A ());
72
+ test (C (a3.begin (), a3.end (), A ()), A ());
73
+ test (C (a4.begin (), a4.end (), A ()), A ());
74
+ test (C (a5.begin (), a5.end (), A ()), A ());
58
75
}
59
- #endif
60
76
61
77
return true ;
62
78
}
0 commit comments