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 // <vector> 11 12 // vector& operator=(vector&& c); 13 14 #include <vector> 15 #include <cassert> 16 #include "test_allocator.h" 17 #include "min_allocator.h" 18 19 int main() 20 { 21 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 22 { 23 std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); 24 std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); 25 for (int i = 1; i <= 3; ++i) 26 { 27 l.push_back(i); 28 lo.push_back(i); 29 } 30 std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(5)); 31 l2 = std::move(l); 32 assert(l2 == lo); 33 assert(l.empty()); 34 assert(l2.get_allocator() == lo.get_allocator()); 35 } 36 { 37 std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); 38 std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); 39 for (int i = 1; i <= 3; ++i) 40 { 41 l.push_back(i); 42 lo.push_back(i); 43 } 44 std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(6)); 45 l2 = std::move(l); 46 assert(l2 == lo); 47 assert(!l.empty()); 48 assert(l2.get_allocator() == test_allocator<bool>(6)); 49 } 50 { 51 std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5)); 52 std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5)); 53 for (int i = 1; i <= 3; ++i) 54 { 55 l.push_back(i); 56 lo.push_back(i); 57 } 58 std::vector<bool, other_allocator<bool> > l2(other_allocator<bool>(6)); 59 l2 = std::move(l); 60 assert(l2 == lo); 61 assert(l.empty()); 62 assert(l2.get_allocator() == lo.get_allocator()); 63 } 64 #if __cplusplus >= 201103L 65 { 66 std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{}); 67 std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{}); 68 for (int i = 1; i <= 3; ++i) 69 { 70 l.push_back(i); 71 lo.push_back(i); 72 } 73 std::vector<bool, min_allocator<bool> > l2(min_allocator<bool>{}); 74 l2 = std::move(l); 75 assert(l2 == lo); 76 assert(l.empty()); 77 assert(l2.get_allocator() == lo.get_allocator()); 78 } 79 #endif 80 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 81 } 82