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// <list>
12
13// list& operator=(list&& c);
14
15#include <list>
16#include <cassert>
17#include "test_macros.h"
18#include "MoveOnly.h"
19#include "test_allocator.h"
20#include "min_allocator.h"
21
22int main(int, char**) {
23 {
24 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
25 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
26 for (int i = 1; i <= 3; ++i) {
27 l.push_back(i);
28 lo.push_back(i);
29 }
30 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
31 std::list<MoveOnly, test_allocator<MoveOnly> >::iterator it = l.begin();
32 l2 = std::move(l);
33 assert(l2 == lo);
34 assert(l.empty());
35 assert(l2.get_allocator() == lo.get_allocator());
36 assert(it == l2.begin()); // Iterators remain valid
37 }
38 {
39 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
40 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
41 for (int i = 1; i <= 3; ++i) {
42 l.push_back(i);
43 lo.push_back(i);
44 }
45 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
46 l2 = std::move(l);
47 assert(l2 == lo);
48 assert(!l.empty());
49 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
50 }
51 {
52 std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
53 std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
54 for (int i = 1; i <= 3; ++i) {
55 l.push_back(i);
56 lo.push_back(i);
57 }
58 std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
59 std::list<MoveOnly, other_allocator<MoveOnly> >::iterator it = l.begin();
60 l2 = std::move(l);
61 assert(l2 == lo);
62 assert(l.empty());
63 assert(l2.get_allocator() == lo.get_allocator());
64 assert(it == l2.begin()); // Iterators remain valid
65 }
66 {
67 std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
68 std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
69 for (int i = 1; i <= 3; ++i) {
70 l.push_back(i);
71 lo.push_back(i);
72 }
73 std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
74 std::list<MoveOnly, min_allocator<MoveOnly> >::iterator it = l.begin();
75 l2 = std::move(l);
76 assert(l2 == lo);
77 assert(l.empty());
78 assert(l2.get_allocator() == lo.get_allocator());
79 assert(it == l2.begin()); // Iterators remain valid
80 }
81
82 return 0;
83}
84

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