move.pass.cpp (2218B)
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 // <forward_list> 13 14 // forward_list(forward_list&& x); 15 16 #include <forward_list> 17 #include <cassert> 18 #include <iterator> 19 20 #include "test_allocator.h" 21 #include "MoveOnly.h" 22 #include "min_allocator.h" 23 24 int main() 25 { 26 { 27 typedef MoveOnly T; 28 typedef test_allocator<T> A; 29 typedef std::forward_list<T, A> C; 30 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 31 typedef std::move_iterator<T*> I; 32 C c0(I(std::begin(t)), I(std::end(t)), A(10)); 33 C c = std::move(c0); 34 int n = 0; 35 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) 36 assert(*i == n); 37 assert(n == std::end(t) - std::begin(t)); 38 assert(c0.empty()); 39 assert(c.get_allocator() == A(10)); 40 } 41 { 42 typedef MoveOnly T; 43 typedef other_allocator<T> A; 44 typedef std::forward_list<T, A> C; 45 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 46 typedef std::move_iterator<T*> I; 47 C c0(I(std::begin(t)), I(std::end(t)), A(10)); 48 C c = std::move(c0); 49 int n = 0; 50 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) 51 assert(*i == n); 52 assert(n == std::end(t) - std::begin(t)); 53 assert(c0.empty()); 54 assert(c.get_allocator() == A(10)); 55 } 56 { 57 typedef MoveOnly T; 58 typedef min_allocator<T> A; 59 typedef std::forward_list<T, A> C; 60 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 61 typedef std::move_iterator<T*> I; 62 C c0(I(std::begin(t)), I(std::end(t)), A()); 63 C c = std::move(c0); 64 int n = 0; 65 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) 66 assert(*i == n); 67 assert(n == std::end(t) - std::begin(t)); 68 assert(c0.empty()); 69 assert(c.get_allocator() == A()); 70 } 71 }