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 "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 const 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(1));
34 for (int* p = ab; p < an; ++p)
35 c2.push_back(MoveOnly(*p));
36 std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
37 assert(c2 == c3);
38 assert(c3.get_allocator() == A(3));
39 LIBCPP_ASSERT(c1.size() != 0);
40 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
41 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
42 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
43 }
44 {
45 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
46 const int* an = ab + sizeof(ab)/sizeof(ab[0]);
47 typedef test_allocator<MoveOnly> A;
48 std::deque<MoveOnly, A> c1(A(1));
49 for (int* p = ab; p < an; ++p)
50 c1.push_back(MoveOnly(*p));
51 std::deque<MoveOnly, A> c2(A(1));
52 for (int* p = ab; p < an; ++p)
53 c2.push_back(MoveOnly(*p));
54 std::deque<MoveOnly, A> c3(std::move(c1), A(1)); // equal allocator
55 assert(c2 == c3);
56 assert(c3.get_allocator() == A(1));
57 LIBCPP_ASSERT(c1.size() == 0);
58 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
59 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
60 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
61 }
62 {
63 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
64 const int* an = ab + sizeof(ab)/sizeof(ab[0]);
65 typedef other_allocator<MoveOnly> A;
66 std::deque<MoveOnly, A> c1(A(1));
67 for (int* p = ab; p < an; ++p)
68 c1.push_back(MoveOnly(*p));
69 std::deque<MoveOnly, A> c2(A(1));
70 for (int* p = ab; p < an; ++p)
71 c2.push_back(MoveOnly(*p));
72 std::deque<MoveOnly, A> c3(std::move(c1), A(3)); // unequal allocator
73 assert(c2 == c3);
74 assert(c3.get_allocator() == A(3));
75 LIBCPP_ASSERT(c1.size() != 0);
76 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
77 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
78 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
79 }
80 {
81 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
82 const int* an = ab + sizeof(ab)/sizeof(ab[0]);
83 typedef min_allocator<MoveOnly> A;
84 std::deque<MoveOnly, A> c1(A{});
85 for (int* p = ab; p < an; ++p)
86 c1.push_back(MoveOnly(*p));
87 std::deque<MoveOnly, A> c2(A{});
88 for (int* p = ab; p < an; ++p)
89 c2.push_back(MoveOnly(*p));
90 std::deque<MoveOnly, A> c3(std::move(c1), A()); // equal allocator
91 assert(c2 == c3);
92 assert(c3.get_allocator() == A());
93 LIBCPP_ASSERT(c1.size() == 0);
94 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
95 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2));
96 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c3));
97 }
98
99 return 0;
100}
101

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