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 // <set> 11 12 // class set 13 14 // set(set&& s, const allocator_type& a); 15 16 #include <set> 17 #include <cassert> 18 19 #include "MoveOnly.h" 20 #include "../../../test_compare.h" 21 #include "test_allocator.h" 22 #include "Counter.h" 23 24 int main() 25 { 26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 27 { 28 typedef MoveOnly V; 29 typedef test_compare<std::less<MoveOnly> > C; 30 typedef test_allocator<V> A; 31 typedef std::set<MoveOnly, C, A> M; 32 typedef std::move_iterator<V*> I; 33 V a1[] = 34 { 35 V(1), 36 V(1), 37 V(1), 38 V(2), 39 V(2), 40 V(2), 41 V(3), 42 V(3), 43 V(3) 44 }; 45 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 46 V a2[] = 47 { 48 V(1), 49 V(1), 50 V(1), 51 V(2), 52 V(2), 53 V(2), 54 V(3), 55 V(3), 56 V(3) 57 }; 58 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 59 M m3(std::move(m1), A(7)); 60 assert(m3 == m2); 61 assert(m3.get_allocator() == A(7)); 62 assert(m3.key_comp() == C(5)); 63 assert(m1.empty()); 64 } 65 { 66 typedef MoveOnly V; 67 typedef test_compare<std::less<MoveOnly> > C; 68 typedef test_allocator<V> A; 69 typedef std::set<MoveOnly, C, A> M; 70 typedef std::move_iterator<V*> I; 71 V a1[] = 72 { 73 V(1), 74 V(1), 75 V(1), 76 V(2), 77 V(2), 78 V(2), 79 V(3), 80 V(3), 81 V(3) 82 }; 83 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 84 V a2[] = 85 { 86 V(1), 87 V(1), 88 V(1), 89 V(2), 90 V(2), 91 V(2), 92 V(3), 93 V(3), 94 V(3) 95 }; 96 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 97 M m3(std::move(m1), A(5)); 98 assert(m3 == m2); 99 assert(m3.get_allocator() == A(5)); 100 assert(m3.key_comp() == C(5)); 101 assert(m1.empty()); 102 } 103 { 104 typedef MoveOnly V; 105 typedef test_compare<std::less<MoveOnly> > C; 106 typedef other_allocator<V> A; 107 typedef std::set<MoveOnly, C, A> M; 108 typedef std::move_iterator<V*> I; 109 V a1[] = 110 { 111 V(1), 112 V(1), 113 V(1), 114 V(2), 115 V(2), 116 V(2), 117 V(3), 118 V(3), 119 V(3) 120 }; 121 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); 122 V a2[] = 123 { 124 V(1), 125 V(1), 126 V(1), 127 V(2), 128 V(2), 129 V(2), 130 V(3), 131 V(3), 132 V(3) 133 }; 134 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); 135 M m3(std::move(m1), A(5)); 136 assert(m3 == m2); 137 assert(m3.get_allocator() == A(5)); 138 assert(m3.key_comp() == C(5)); 139 assert(m1.empty()); 140 } 141 { 142 typedef Counter<int> V; 143 typedef std::less<V> C; 144 typedef test_allocator<V> A; 145 typedef std::set<V, C, A> M; 146 typedef V* I; 147 Counter_base::gConstructed = 0; 148 { 149 V a1[] = 150 { 151 V(1), 152 V(1), 153 V(1), 154 V(2), 155 V(2), 156 V(2), 157 V(3), 158 V(3), 159 V(3) 160 }; 161 const size_t num = sizeof(a1)/sizeof(a1[0]); 162 assert(Counter_base::gConstructed == num); 163 164 M m1(I(a1), I(a1+num), C(), A()); 165 assert(Counter_base::gConstructed == 3+num); 166 167 M m2(m1); 168 assert(m2 == m1); 169 assert(Counter_base::gConstructed == 6+num); 170 171 M m3(std::move(m1), A()); 172 assert(m3 == m2); 173 assert(m1.empty()); 174 assert(Counter_base::gConstructed == 6+num); 175 176 { 177 M m4(std::move(m2), A(5)); 178 assert(Counter_base::gConstructed == 6+num); 179 assert(m4 == m3); 180 assert(m2.empty()); 181 } 182 assert(Counter_base::gConstructed == 3+num); 183 } 184 assert(Counter_base::gConstructed == 0); 185 } 186 187 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 188 } 189