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
24int 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(test_alloc_base::moved_value));
42 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
43 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
44 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
45 }
46 {
47 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
48 int* an = ab + sizeof(ab)/sizeof(ab[0]);
49 typedef other_allocator<MoveOnly> A;
50 std::deque<MoveOnly, A> c1(A(1));
51 for (int* p = ab; p < an; ++p)
52 c1.push_back(MoveOnly(*p));
53 std::deque<MoveOnly, A> c2(A(2));
54 for (int* p = ab; p < an; ++p)
55 c2.push_back(MoveOnly(*p));
56 std::deque<MoveOnly, A> c3 = std::move(c1);
57 assert(c2 == c3);
58 assert(c1.size() == 0);
59 assert(c3.get_allocator() == c1.get_allocator());
60 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
61 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
62 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
63 }
64 {
65 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
66 int* an = ab + sizeof(ab)/sizeof(ab[0]);
67 typedef min_allocator<MoveOnly> A;
68 std::deque<MoveOnly, A> c1(A{});
69 for (int* p = ab; p < an; ++p)
70 c1.push_back(MoveOnly(*p));
71 std::deque<MoveOnly, A> c2(A{});
72 for (int* p = ab; p < an; ++p)
73 c2.push_back(MoveOnly(*p));
74 std::deque<MoveOnly, A> c3 = std::move(c1);
75 assert(c2 == c3);
76 assert(c1.size() == 0);
77 assert(c3.get_allocator() == c1.get_allocator());
78 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
79 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
80 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
81 }
82
83 return 0;
84}
85

source code of libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp