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(list&& c); 13 14 #include <list> 15 #include <cassert> 16 #include "../../../MoveOnly.h" 17 #include "test_allocator.h" 18 #include "min_allocator.h" 19 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 = std::move(l); 32 assert(l2 == lo); 33 assert(l.empty()); 34 assert(l2.get_allocator() == lo.get_allocator()); 35 } 36 { 37 std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); 38 std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); 39 for (int i = 1; i <= 3; ++i) 40 { 41 l.push_back(i); 42 lo.push_back(i); 43 } 44 std::list<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l); 45 assert(l2 == lo); 46 assert(l.empty()); 47 assert(l2.get_allocator() == lo.get_allocator()); 48 } 49 #if __cplusplus >= 201103L 50 { 51 std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); 52 std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); 53 for (int i = 1; i <= 3; ++i) 54 { 55 l.push_back(i); 56 lo.push_back(i); 57 } 58 std::list<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l); 59 assert(l2 == lo); 60 assert(l.empty()); 61 assert(l2.get_allocator() == lo.get_allocator()); 62 } 63 #endif 64 #if _LIBCPP_DEBUG >= 1 65 { 66 std::list<int> l1 = {1, 2, 3}; 67 std::list<int>::iterator i = l1.begin(); 68 std::list<int> l2 = std::move(l1); 69 assert(*l2.erase(i) == 2); 70 assert(l2.size() == 2); 71 } 72 #endif 73 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 74 } 75