assign_move.pass.cpp (2672B)
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 // UNSUPPORTED: c++98, c++03 11 12 // <list> 13 14 // list& operator=(list&& c); 15 16 #include <list> 17 #include <cassert> 18 #include "MoveOnly.h" 19 #include "test_allocator.h" 20 #include "min_allocator.h" 21 22 int main() 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 l2 = std::move(l); 34 assert(l2 == lo); 35 assert(l.empty()); 36 assert(l2.get_allocator() == lo.get_allocator()); 37 } 38 { 39 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); 40 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); 41 for (int i = 1; i <= 3; ++i) 42 { 43 l.push_back(i); 44 lo.push_back(i); 45 } 46 std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6)); 47 l2 = std::move(l); 48 assert(l2 == lo); 49 assert(!l.empty()); 50 assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); 51 } 52 { 53 std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); 54 std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); 55 for (int i = 1; i <= 3; ++i) 56 { 57 l.push_back(i); 58 lo.push_back(i); 59 } 60 std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6)); 61 l2 = std::move(l); 62 assert(l2 == lo); 63 assert(l.empty()); 64 assert(l2.get_allocator() == lo.get_allocator()); 65 } 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 }