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 // <vector> 10 // vector<bool> 11 12 // void swap(vector& x); 13 14 #include <vector> 15 #include <cassert> 16 #include "test_allocator.h" 17 #include "min_allocator.h" 18 19 int main(int, char**) 20 { 21 { 22 std::vector<bool> v1(100); 23 std::vector<bool> v2(200); 24 v1.swap(v2); 25 assert(v1.size() == 200); 26 assert(v1.capacity() >= 200); 27 assert(v2.size() == 100); 28 assert(v2.capacity() >= 100); 29 } 30 { 31 typedef test_allocator<bool> A; 32 std::vector<bool, A> v1(100, true, A(1, 1)); 33 std::vector<bool, A> v2(200, false, A(1, 2)); 34 swap(v1, v2); 35 assert(v1.size() == 200); 36 assert(v1.capacity() >= 200); 37 assert(v2.size() == 100); 38 assert(v2.capacity() >= 100); 39 assert(v1.get_allocator().get_id() == 1); 40 assert(v2.get_allocator().get_id() == 2); 41 } 42 { 43 typedef other_allocator<bool> A; 44 std::vector<bool, A> v1(100, true, A(1)); 45 std::vector<bool, A> v2(200, false, A(2)); 46 swap(v1, v2); 47 assert(v1.size() == 200); 48 assert(v1.capacity() >= 200); 49 assert(v2.size() == 100); 50 assert(v2.capacity() >= 100); 51 assert(v1.get_allocator() == A(2)); 52 assert(v2.get_allocator() == A(1)); 53 } 54 { 55 std::vector<bool> v(2); 56 std::vector<bool>::reference r1 = v[0]; 57 std::vector<bool>::reference r2 = v[1]; 58 r1 = true; 59 using std::swap; 60 swap(r1, r2); 61 assert(v[0] == false); 62 assert(v[1] == true); 63 } 64 #if TEST_STD_VER >= 11 65 { 66 std::vector<bool, min_allocator<bool>> v1(100); 67 std::vector<bool, min_allocator<bool>> v2(200); 68 v1.swap(v2); 69 assert(v1.size() == 200); 70 assert(v1.capacity() >= 200); 71 assert(v2.size() == 100); 72 assert(v2.capacity() >= 100); 73 } 74 { 75 typedef min_allocator<bool> A; 76 std::vector<bool, A> v1(100, true, A()); 77 std::vector<bool, A> v2(200, false, A()); 78 swap(v1, v2); 79 assert(v1.size() == 200); 80 assert(v1.capacity() >= 200); 81 assert(v2.size() == 100); 82 assert(v2.capacity() >= 100); 83 assert(v1.get_allocator() == A()); 84 assert(v2.get_allocator() == A()); 85 } 86 { 87 std::vector<bool, min_allocator<bool>> v(2); 88 std::vector<bool, min_allocator<bool>>::reference r1 = v[0]; 89 std::vector<bool, min_allocator<bool>>::reference r2 = v[1]; 90 r1 = true; 91 using std::swap; 92 swap(r1, r2); 93 assert(v[0] == false); 94 assert(v[1] == true); 95 } 96 #endif 97 98 return 0; 99 } 100