• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <vector>
11 // vector<bool>
12 
13 // void swap(vector& x);
14 
15 #include <vector>
16 #include <cassert>
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19 
main()20 int main()
21 {
22     {
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);
30     }
31     {
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);
42     }
43     {
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));
54     }
55     {
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);
64     }
65 #if TEST_STD_VER >= 11
66     {
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);
74     }
75     {
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());
86     }
87     {
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);
96     }
97 #endif
98 }
99