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 {
25 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
26 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
27 for (int i = 1; i <= 3; ++i)
28 {
29 l.push_back(i);
30 lo.push_back(i);
31 }
32 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
33 std::list<MoveOnly, test_allocator<MoveOnly> >::iterator it = l.begin();
34 l2 = std::move(l);
35 assert(l2 == lo);
36 assert(l.empty());
37 assert(l2.get_allocator() == lo.get_allocator());
38 assert(it == l2.begin()); // Iterators remain valid
39 }
40 {
41 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
42 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
43 for (int i = 1; i <= 3; ++i)
44 {
45 l.push_back(i);
46 lo.push_back(i);
47 }
48 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6));
49 l2 = std::move(l);
50 assert(l2 == lo);
51 assert(!l.empty());
52 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
53 }
54 {
55 std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
56 std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
57 for (int i = 1; i <= 3; ++i)
58 {
59 l.push_back(i);
60 lo.push_back(i);
61 }
62 std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
63 std::list<MoveOnly, other_allocator<MoveOnly> >::iterator it = l.begin();
64 l2 = std::move(l);
65 assert(l2 == lo);
66 assert(l.empty());
67 assert(l2.get_allocator() == lo.get_allocator());
68 assert(it == l2.begin()); // Iterators remain valid
69 }
70 {
71 std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
72 std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
73 for (int i = 1; i <= 3; ++i)
74 {
75 l.push_back(i);
76 lo.push_back(i);
77 }
78 std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
79 std::list<MoveOnly, min_allocator<MoveOnly> >::iterator it = l.begin();
80 l2 = std::move(l);
81 assert(l2 == lo);
82 assert(l.empty());
83 assert(l2.get_allocator() == lo.get_allocator());
84 assert(it == l2.begin()); // Iterators remain valid
85 }
86
87 return 0;
88}
89

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