1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class T, class A>
12 // void swap(deque<T, A>& x, deque<T, A>& y);
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
22 make(int size
, int start
= 0 )
24 const int b
= 4096 / sizeof(int);
28 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
33 for (int i
= 0; i
< init
-start
; ++i
)
35 for (int i
= 0; i
< size
; ++i
)
37 for (int i
= 0; i
< start
; ++i
)
43 void testN(int start
, int N
, int M
)
45 C c1
= make
<C
>(N
, start
);
50 assert(c1
== c2_save
);
51 assert(c2
== c1_save
);
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));
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));
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());
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());