|
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 | 14 | #include <cassert> |
| 15 | +#include <vector> |
15 | 16 |
|
16 | | -#include "test_macros.h" |
17 | | -#include "test_allocator.h" |
18 | 17 | #include "min_allocator.h" |
| 18 | +#include "test_allocator.h" |
| 19 | +#include "test_macros.h" |
19 | 20 |
|
20 | | -template <class C> |
21 | | -TEST_CONSTEXPR_CXX20 void test(const C& x, const typename C::allocator_type& a) |
22 | | -{ |
23 | | - typename C::size_type s = x.size(); |
24 | | - C c(x, a); |
25 | | - LIBCPP_ASSERT(c.__invariants()); |
26 | | - assert(c.size() == s); |
27 | | - assert(c == x); |
| 21 | +template <class A> |
| 22 | +TEST_CONSTEXPR_CXX20 void test(const std::vector<bool, A>& x, const A& a) { |
| 23 | + std::vector<bool, A> c(x, a); |
| 24 | + LIBCPP_ASSERT(c.__invariants()); |
| 25 | + assert(c.size() == x.size()); |
| 26 | + assert(c == x); |
| 27 | + assert(c.get_allocator() == a); |
28 | 28 | } |
29 | 29 |
|
30 | | -TEST_CONSTEXPR_CXX20 bool tests() |
31 | | -{ |
32 | | - { |
33 | | - bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; |
34 | | - bool* an = a + sizeof(a)/sizeof(a[0]); |
35 | | - test(std::vector<bool>(a, an), std::allocator<bool>()); |
36 | | - } |
37 | | - { |
38 | | - std::vector<bool, test_allocator<bool> > l(3, true, test_allocator<bool>(5)); |
39 | | - std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3)); |
40 | | - assert(l2 == l); |
41 | | - assert(l2.get_allocator() == test_allocator<bool>(3)); |
42 | | - } |
43 | | - { |
44 | | - std::vector<bool, other_allocator<bool> > l(3, true, other_allocator<bool>(5)); |
45 | | - std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3)); |
46 | | - assert(l2 == l); |
47 | | - assert(l2.get_allocator() == other_allocator<bool>(3)); |
48 | | - } |
49 | | -#if TEST_STD_VER >= 11 |
50 | | - { |
51 | | - bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; |
52 | | - bool* an = a + sizeof(a)/sizeof(a[0]); |
53 | | - test(std::vector<bool, min_allocator<bool>>(a, an), min_allocator<bool>()); |
54 | | - } |
55 | | - { |
56 | | - std::vector<bool, min_allocator<bool> > l(3, true, min_allocator<bool>()); |
57 | | - std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>()); |
58 | | - assert(l2 == l); |
59 | | - assert(l2.get_allocator() == min_allocator<bool>()); |
60 | | - } |
61 | | -#endif |
| 30 | +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}; |
| 35 | + |
| 36 | + { // 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>()); |
| 41 | + test(std::vector<bool>(257, true), std::allocator<bool>()); |
| 42 | + } |
| 43 | + |
| 44 | + { // Test with test_allocator |
| 45 | + using A = test_allocator<bool>; |
| 46 | + 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)); |
| 51 | + test(C(257, true, A(5)), A(3)); |
| 52 | + } |
| 53 | + |
| 54 | + { // Test with other_allocator |
| 55 | + using A = other_allocator<bool>; |
| 56 | + 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)); |
| 61 | + test(C(257, true, A(5)), A(3)); |
| 62 | + } |
| 63 | + |
| 64 | + { // Test with min_allocator |
| 65 | + using A = min_allocator<bool>; |
| 66 | + 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()); |
| 71 | + test(C(257, true, A()), A()); |
| 72 | + } |
62 | 73 |
|
63 | 74 | return true; |
64 | 75 | } |
65 | 76 |
|
66 | | -int main(int, char**) |
67 | | -{ |
68 | | - tests(); |
69 | | -#if TEST_STD_VER > 17 |
70 | | - static_assert(tests()); |
| 77 | +int main(int, char**) { |
| 78 | + tests(); |
| 79 | +#if TEST_STD_VER >= 20 |
| 80 | + static_assert(tests()); |
71 | 81 | #endif |
72 | | - return 0; |
| 82 | + return 0; |
73 | 83 | } |
0 commit comments