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 && !stdlib=libc++
10
11// <vector>
12
13// vector& operator=(vector&& c);
14
15#include <vector>
16#include <cassert>
17#include "test_macros.h"
18#include "MoveOnly.h"
19#include "test_allocator.h"
20#include "min_allocator.h"
21#include "asan_testing.h"
22
23TEST_CONSTEXPR_CXX20 bool tests() {
24 {
25 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
26 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
27 for (int i = 1; i <= 3; ++i) {
28 l.push_back(i);
29 lo.push_back(i);
30 }
31 assert(is_contiguous_container_asan_correct(l));
32 assert(is_contiguous_container_asan_correct(lo));
33 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
34 l2 = std::move(l);
35 assert(l2 == lo);
36 assert(l.empty());
37 assert(l2.get_allocator() == lo.get_allocator());
38 assert(is_contiguous_container_asan_correct(l2));
39 }
40 {
41 std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
42 std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
43 assert(is_contiguous_container_asan_correct(l));
44 assert(is_contiguous_container_asan_correct(lo));
45 for (int i = 1; i <= 3; ++i) {
46 l.push_back(i);
47 lo.push_back(i);
48 }
49 assert(is_contiguous_container_asan_correct(l));
50 assert(is_contiguous_container_asan_correct(lo));
51 std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
52 l2 = std::move(l);
53 assert(l2 == lo);
54 assert(!l.empty());
55 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
56 assert(is_contiguous_container_asan_correct(l2));
57 }
58 {
59 std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
60 std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
61 assert(is_contiguous_container_asan_correct(l));
62 assert(is_contiguous_container_asan_correct(lo));
63 for (int i = 1; i <= 3; ++i) {
64 l.push_back(i);
65 lo.push_back(i);
66 }
67 assert(is_contiguous_container_asan_correct(l));
68 assert(is_contiguous_container_asan_correct(lo));
69 std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
70 l2 = std::move(l);
71 assert(l2 == lo);
72 assert(l.empty());
73 assert(l2.get_allocator() == lo.get_allocator());
74 assert(is_contiguous_container_asan_correct(l2));
75 }
76 {
77 std::vector<MoveOnly, min_allocator<MoveOnly> > l((min_allocator<MoveOnly>()));
78 std::vector<MoveOnly, min_allocator<MoveOnly> > lo((min_allocator<MoveOnly>()));
79 assert(is_contiguous_container_asan_correct(l));
80 assert(is_contiguous_container_asan_correct(lo));
81 for (int i = 1; i <= 3; ++i) {
82 l.push_back(i);
83 lo.push_back(i);
84 }
85 assert(is_contiguous_container_asan_correct(l));
86 assert(is_contiguous_container_asan_correct(lo));
87 std::vector<MoveOnly, min_allocator<MoveOnly> > l2((min_allocator<MoveOnly>()));
88 l2 = std::move(l);
89 assert(l2 == lo);
90 assert(l.empty());
91 assert(l2.get_allocator() == lo.get_allocator());
92 assert(is_contiguous_container_asan_correct(l2));
93 }
94 {
95 std::vector<MoveOnly, safe_allocator<MoveOnly> > l((safe_allocator<MoveOnly>()));
96 std::vector<MoveOnly, safe_allocator<MoveOnly> > lo((safe_allocator<MoveOnly>()));
97 assert(is_contiguous_container_asan_correct(l));
98 assert(is_contiguous_container_asan_correct(lo));
99 for (int i = 1; i <= 3; ++i) {
100 l.push_back(i);
101 lo.push_back(i);
102 }
103 assert(is_contiguous_container_asan_correct(l));
104 assert(is_contiguous_container_asan_correct(lo));
105 std::vector<MoveOnly, safe_allocator<MoveOnly> > l2((safe_allocator<MoveOnly>()));
106 l2 = std::move(l);
107 assert(l2 == lo);
108 assert(l.empty());
109 assert(l2.get_allocator() == lo.get_allocator());
110 assert(is_contiguous_container_asan_correct(l2));
111 }
112
113 return true;
114}
115
116int main(int, char**) {
117 tests();
118#if TEST_STD_VER > 17
119 static_assert(tests());
120#endif
121 return 0;
122}
123

source code of libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp