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