[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.special / swap.pass.cpp
blob61fa31c5e05c8dc2cd5132f15b5dabb15c557f87
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 // <deque>
11 // template <class T, class A>
12 // void swap(deque<T, A>& x, deque<T, A>& y);
14 #include <deque>
15 #include <cassert>
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
20 template <class C>
22 make(int size, int start = 0 )
24 const int b = 4096 / sizeof(int);
25 int init = 0;
26 if (start > 0)
28 init = (start+1) / b + ((start+1) % b != 0);
29 init *= b;
30 --init;
32 C c(init, 0);
33 for (int i = 0; i < init-start; ++i)
34 c.pop_back();
35 for (int i = 0; i < size; ++i)
36 c.push_back(i);
37 for (int i = 0; i < start; ++i)
38 c.pop_front();
39 return c;
42 template <class C>
43 void testN(int start, int N, int M)
45 C c1 = make<C>(N, start);
46 C c2 = make<C>(M);
47 C c1_save = c1;
48 C c2_save = c2;
49 swap(c1, c2);
50 assert(c1 == c2_save);
51 assert(c2 == c1_save);
54 int main(int, char**)
57 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
58 const int N = sizeof(rng)/sizeof(rng[0]);
59 for (int i = 0; i < N; ++i)
60 for (int j = 0; j < N; ++j)
61 for (int k = 0; k < N; ++k)
62 testN<std::deque<int> >(rng[i], rng[j], rng[k]);
65 int a1[] = {1, 3, 7, 9, 10};
66 int a2[] = {0, 2, 4, 5, 6, 8, 11};
67 typedef test_allocator<int> A;
68 std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1, 1));
69 std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(1, 2));
70 swap(c1, c2);
71 assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
72 assert(c1.get_allocator().get_id() == 1);
73 assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
74 assert(c2.get_allocator().get_id() == 2);
77 int a1[] = {1, 3, 7, 9, 10};
78 int a2[] = {0, 2, 4, 5, 6, 8, 11};
79 typedef other_allocator<int> A;
80 std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1));
81 std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2));
82 swap(c1, c2);
83 assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
84 assert(c1.get_allocator() == A(2));
85 assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
86 assert(c2.get_allocator() == A(1));
88 #if TEST_STD_VER >= 11
90 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
91 const int N = sizeof(rng)/sizeof(rng[0]);
92 for (int i = 0; i < N; ++i)
93 for (int j = 0; j < N; ++j)
94 for (int k = 0; k < N; ++k)
95 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]);
98 int a1[] = {1, 3, 7, 9, 10};
99 int a2[] = {0, 2, 4, 5, 6, 8, 11};
100 typedef min_allocator<int> A;
101 std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A());
102 std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A());
103 swap(c1, c2);
104 assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
105 assert(c1.get_allocator() == A());
106 assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
107 assert(c2.get_allocator() == A());
109 #endif
111 return 0;