1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <list>
11
12 // list& operator=(list&& c);
13
14 #include <list>
15 #include <cassert>
16 #include "MoveOnly.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19
main()20 int main()
21 {
22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 {
28 l.push_back(i);
29 lo.push_back(i);
30 }
31 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5));
32 l2 = std::move(l);
33 assert(l2 == lo);
34 assert(l.empty());
35 assert(l2.get_allocator() == lo.get_allocator());
36 }
37 {
38 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
39 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
40 for (int i = 1; i <= 3; ++i)
41 {
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 {
56 l.push_back(i);
57 lo.push_back(i);
58 }
59 std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6));
60 l2 = std::move(l);
61 assert(l2 == lo);
62 assert(l.empty());
63 assert(l2.get_allocator() == lo.get_allocator());
64 }
65 #if __cplusplus >= 201103L
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 {
71 l.push_back(i);
72 lo.push_back(i);
73 }
74 std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
75 l2 = std::move(l);
76 assert(l2 == lo);
77 assert(l.empty());
78 assert(l2.get_allocator() == lo.get_allocator());
79 }
80 #endif
81 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
82 }
83