blob: 703efb8bf1472970cf211a09cb7c014792b9ef1c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <forward_list>
11
12// forward_list& operator=(forward_list&& x);
13
14#include <forward_list>
15#include <cassert>
16#include <iterator>
17
18#include "../../../test_allocator.h"
19#include "../../../MoveOnly.h"
20
21int main()
22{
Howard Hinnant73d21a42010-09-04 23:28:19 +000023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024 {
25 typedef MoveOnly T;
26 typedef test_allocator<T> A;
27 typedef std::forward_list<T, A> C;
28 T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
29 T t1[] = {10, 11, 12, 13};
30 typedef std::move_iterator<T*> I;
31 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
32 C c1(I(std::begin(t1)), I(std::end(t1)), A(10));
33 c1 = std::move(c0);
34 int n = 0;
35 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
36 assert(*i == n);
37 assert(n == 10);
38 assert(c1.get_allocator() == A(10));
39 assert(c0.empty());
40 }
41 {
42 typedef MoveOnly T;
43 typedef test_allocator<T> A;
44 typedef std::forward_list<T, A> C;
45 T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
46 T t1[] = {10, 11, 12, 13};
47 typedef std::move_iterator<T*> I;
48 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
49 C c1(I(std::begin(t1)), I(std::end(t1)), A(11));
50 c1 = std::move(c0);
51 int n = 0;
52 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
53 assert(*i == n);
54 assert(n == 10);
55 assert(c1.get_allocator() == A(11));
56 assert(!c0.empty());
57 }
58 {
59 typedef MoveOnly T;
60 typedef test_allocator<T> A;
61 typedef std::forward_list<T, A> C;
62 T t0[] = {10, 11, 12, 13};
63 T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
64 typedef std::move_iterator<T*> I;
65 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
66 C c1(I(std::begin(t1)), I(std::end(t1)), A(10));
67 c1 = std::move(c0);
68 int n = 0;
69 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
70 assert(*i == 10+n);
71 assert(n == 4);
72 assert(c1.get_allocator() == A(10));
73 assert(c0.empty());
74 }
75 {
76 typedef MoveOnly T;
77 typedef test_allocator<T> A;
78 typedef std::forward_list<T, A> C;
79 T t0[] = {10, 11, 12, 13};
80 T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
81 typedef std::move_iterator<T*> I;
82 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
83 C c1(I(std::begin(t1)), I(std::end(t1)), A(11));
84 c1 = std::move(c0);
85 int n = 0;
86 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
87 assert(*i == 10+n);
88 assert(n == 4);
89 assert(c1.get_allocator() == A(11));
90 assert(!c0.empty());
91 }
92
93 {
94 typedef MoveOnly T;
95 typedef other_allocator<T> A;
96 typedef std::forward_list<T, A> C;
97 T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
98 T t1[] = {10, 11, 12, 13};
99 typedef std::move_iterator<T*> I;
100 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
101 C c1(I(std::begin(t1)), I(std::end(t1)), A(10));
102 c1 = std::move(c0);
103 int n = 0;
104 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
105 assert(*i == n);
106 assert(n == 10);
107 assert(c1.get_allocator() == A(10));
108 assert(c0.empty());
109 }
110 {
111 typedef MoveOnly T;
112 typedef other_allocator<T> A;
113 typedef std::forward_list<T, A> C;
114 T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
115 T t1[] = {10, 11, 12, 13};
116 typedef std::move_iterator<T*> I;
117 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
118 C c1(I(std::begin(t1)), I(std::end(t1)), A(11));
119 c1 = std::move(c0);
120 int n = 0;
121 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
122 assert(*i == n);
123 assert(n == 10);
124 assert(c1.get_allocator() == A(10));
125 assert(c0.empty());
126 }
127 {
128 typedef MoveOnly T;
129 typedef other_allocator<T> A;
130 typedef std::forward_list<T, A> C;
131 T t0[] = {10, 11, 12, 13};
132 T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
133 typedef std::move_iterator<T*> I;
134 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
135 C c1(I(std::begin(t1)), I(std::end(t1)), A(10));
136 c1 = std::move(c0);
137 int n = 0;
138 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
139 assert(*i == 10+n);
140 assert(n == 4);
141 assert(c1.get_allocator() == A(10));
142 assert(c0.empty());
143 }
144 {
145 typedef MoveOnly T;
146 typedef other_allocator<T> A;
147 typedef std::forward_list<T, A> C;
148 T t0[] = {10, 11, 12, 13};
149 T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
150 typedef std::move_iterator<T*> I;
151 C c0(I(std::begin(t0)), I(std::end(t0)), A(10));
152 C c1(I(std::begin(t1)), I(std::end(t1)), A(11));
153 c1 = std::move(c0);
154 int n = 0;
155 for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
156 assert(*i == 10+n);
157 assert(n == 4);
158 assert(c1.get_allocator() == A(10));
159 assert(c0.empty());
160 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000161#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000162}