1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10
11// <vector>
12// vector<bool>
13
14// vector(vector&& c, const allocator_type& a);
15
16#include <array>
17#include <cassert>
18#include <vector>
19
20#include "min_allocator.h"
21#include "test_allocator.h"
22#include "test_macros.h"
23
24template <unsigned N, class A>
25TEST_CONSTEXPR_CXX20 void test(const A& a, const A& a0) {
26 std::vector<bool, A> v(N, false, a);
27 std::vector<bool, A> original(N, false, a0);
28 for (unsigned i = 1; i < N; i += 2) {
29 v[i] = true;
30 original[i] = true;
31 }
32 std::vector<bool, A> v2(std::move(v), a0);
33 assert(v2 == original);
34 assert(v2.get_allocator() == a0);
35 if (a == a0)
36 assert(v.empty()); // After container-move, the vector is guaranteed to be empty
37 else
38 LIBCPP_ASSERT(!v.empty()); // After element-wise move, the RHS vector is not necessarily empty
39}
40
41TEST_CONSTEXPR_CXX20 bool tests() {
42 { // Test with default allocator: compatible allocators
43 using A = std::allocator<bool>;
44 test<5>(A(), A());
45 test<17>(A(), A());
46 test<65>(A(), A());
47 test<299>(A(), A());
48 }
49 { // Test with test_allocator: compatible and incompatible allocators
50 using A = test_allocator<bool>;
51
52 // Compatible allocators
53 test<5>(A(5), A(5));
54 test<17>(A(5), A(5));
55 test<65>(A(5), A(5));
56 test<299>(A(5), A(5));
57
58 // Incompatible allocators
59 test<5>(A(5), A(6));
60 test<17>(A(5), A(6));
61 test<65>(A(5), A(6));
62 test<299>(A(5), A(6));
63 }
64 { // Test with other_allocator: compatible and incompatible allocators
65 using A = other_allocator<bool>;
66
67 // Compatible allocators
68 test<5>(A(5), A(5));
69 test<17>(A(5), A(5));
70 test<65>(A(5), A(5));
71 test<299>(A(5), A(5));
72
73 // Incompatible allocators
74 test<5>(A(5), A(3));
75 test<17>(A(5), A(3));
76 test<65>(A(5), A(3));
77 test<299>(A(5), A(3));
78 }
79 { // Test with min_allocator: compatible allocators
80 using A = min_allocator<bool>;
81 test<5>(A(), A());
82 test<17>(A(), A());
83 test<65>(A(), A());
84 test<299>(A(), A());
85 }
86
87 return true;
88}
89
90int main(int, char**) {
91 tests();
92#if TEST_STD_VER > 17
93 static_assert(tests());
94#endif
95 return 0;
96}
97

source code of libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp