[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / vector.bool / swap.pass.cpp
blob6dbd08cea9520e1ce13faebd3c6fee40b429fd74
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 //===----------------------------------------------------------------------===//
9 // <vector>
10 // vector<bool>
12 // void swap(vector& x);
14 #include <vector>
15 #include <cassert>
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
20 int main(int, char**)
23 std::vector<bool> v1(100);
24 std::vector<bool> v2(200);
25 v1.swap(v2);
26 assert(v1.size() == 200);
27 assert(v1.capacity() >= 200);
28 assert(v2.size() == 100);
29 assert(v2.capacity() >= 100);
32 typedef test_allocator<bool> A;
33 std::vector<bool, A> v1(100, true, A(1, 1));
34 std::vector<bool, A> v2(200, false, A(1, 2));
35 swap(v1, v2);
36 assert(v1.size() == 200);
37 assert(v1.capacity() >= 200);
38 assert(v2.size() == 100);
39 assert(v2.capacity() >= 100);
40 assert(v1.get_allocator().get_id() == 1);
41 assert(v2.get_allocator().get_id() == 2);
44 typedef other_allocator<bool> A;
45 std::vector<bool, A> v1(100, true, A(1));
46 std::vector<bool, A> v2(200, false, A(2));
47 swap(v1, v2);
48 assert(v1.size() == 200);
49 assert(v1.capacity() >= 200);
50 assert(v2.size() == 100);
51 assert(v2.capacity() >= 100);
52 assert(v1.get_allocator() == A(2));
53 assert(v2.get_allocator() == A(1));
56 std::vector<bool> v(2);
57 std::vector<bool>::reference r1 = v[0];
58 std::vector<bool>::reference r2 = v[1];
59 r1 = true;
60 using std::swap;
61 swap(r1, r2);
62 assert(v[0] == false);
63 assert(v[1] == true);
65 #if TEST_STD_VER >= 11
67 std::vector<bool, min_allocator<bool>> v1(100);
68 std::vector<bool, min_allocator<bool>> v2(200);
69 v1.swap(v2);
70 assert(v1.size() == 200);
71 assert(v1.capacity() >= 200);
72 assert(v2.size() == 100);
73 assert(v2.capacity() >= 100);
76 typedef min_allocator<bool> A;
77 std::vector<bool, A> v1(100, true, A());
78 std::vector<bool, A> v2(200, false, A());
79 swap(v1, v2);
80 assert(v1.size() == 200);
81 assert(v1.capacity() >= 200);
82 assert(v2.size() == 100);
83 assert(v2.capacity() >= 100);
84 assert(v1.get_allocator() == A());
85 assert(v2.get_allocator() == A());
88 std::vector<bool, min_allocator<bool>> v(2);
89 std::vector<bool, min_allocator<bool>>::reference r1 = v[0];
90 std::vector<bool, min_allocator<bool>>::reference r2 = v[1];
91 r1 = true;
92 using std::swap;
93 swap(r1, r2);
94 assert(v[0] == false);
95 assert(v[1] == true);
97 #endif
99 return 0;