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 // UNSUPPORTED: c++03
10 
11 // <deque>
12 
13 // deque(deque&& c, const allocator_type& a);
14 
15 #include <deque>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "MoveOnly.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
27         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
28         typedef test_allocator<MoveOnly> A;
29         std::deque<MoveOnly, A> c1(A(1));
30         for (int* p = ab; p < an; ++p)
31             c1.push_back(MoveOnly(*p));
32         std::deque<MoveOnly, A> c2(A(1));
33         for (int* p = ab; p < an; ++p)
34             c2.push_back(MoveOnly(*p));
35         std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
36         assert(c2 == c3);
37         assert(c3.get_allocator() == A(3));
38         LIBCPP_ASSERT(c1.size() != 0);
39     }
40     {
41         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
42         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
43         typedef test_allocator<MoveOnly> A;
44         std::deque<MoveOnly, A> c1(A(1));
45         for (int* p = ab; p < an; ++p)
46             c1.push_back(MoveOnly(*p));
47         std::deque<MoveOnly, A> c2(A(1));
48         for (int* p = ab; p < an; ++p)
49             c2.push_back(MoveOnly(*p));
50         std::deque<MoveOnly, A> c3(std::move(c1), A(1)); // equal allocator
51         assert(c2 == c3);
52         assert(c3.get_allocator() == A(1));
53         LIBCPP_ASSERT(c1.size() == 0);
54     }
55     {
56         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
57         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
58         typedef other_allocator<MoveOnly> A;
59         std::deque<MoveOnly, A> c1(A(1));
60         for (int* p = ab; p < an; ++p)
61             c1.push_back(MoveOnly(*p));
62         std::deque<MoveOnly, A> c2(A(1));
63         for (int* p = ab; p < an; ++p)
64             c2.push_back(MoveOnly(*p));
65         std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
66         assert(c2 == c3);
67         assert(c3.get_allocator() == A(3));
68         LIBCPP_ASSERT(c1.size() != 0);
69     }
70     {
71         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
72         const int* an = ab + sizeof(ab)/sizeof(ab[0]);
73         typedef min_allocator<MoveOnly> A;
74         std::deque<MoveOnly, A> c1(A{});
75         for (int* p = ab; p < an; ++p)
76             c1.push_back(MoveOnly(*p));
77         std::deque<MoveOnly, A> c2(A{});
78         for (int* p = ab; p < an; ++p)
79             c2.push_back(MoveOnly(*p));
80         std::deque<MoveOnly, A> c3(std::move(c1), A());  // equal allocator
81         assert(c2 == c3);
82         assert(c3.get_allocator() == A());
83         LIBCPP_ASSERT(c1.size() == 0);
84     }
85 
86   return 0;
87 }
88