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