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 // <forward_list> 11 12 // forward_list(forward_list&& x, const allocator_type& a); 13 14 #include <forward_list> 15 #include <cassert> 16 #include <iterator> 17 18 #include "test_allocator.h" 19 #include "../../../MoveOnly.h" 20 #include "min_allocator.h" 21 22 int main() 23 { 24 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 25 { 26 typedef MoveOnly T; 27 typedef test_allocator<int> A; 28 typedef std::forward_list<T, A> C; 29 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 30 typedef std::move_iterator<T*> I; 31 C c0(I(std::begin(t)), I(std::end(t)), A(10)); 32 C c(std::move(c0), A(10)); 33 unsigned n = 0; 34 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) 35 assert(*i == n); 36 assert(n == std::end(t) - std::begin(t)); 37 assert(c0.empty()); 38 assert(c.get_allocator() == A(10)); 39 } 40 { 41 typedef MoveOnly T; 42 typedef test_allocator<int> A; 43 typedef std::forward_list<T, A> C; 44 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 45 typedef std::move_iterator<T*> I; 46 C c0(I(std::begin(t)), I(std::end(t)), A(10)); 47 C c(std::move(c0), A(9)); 48 unsigned n = 0; 49 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) 50 assert(*i == n); 51 assert(n == std::end(t) - std::begin(t)); 52 assert(!c0.empty()); 53 assert(c.get_allocator() == A(9)); 54 } 55 #if __cplusplus >= 201103L 56 { 57 typedef MoveOnly T; 58 typedef min_allocator<int> 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), A()); 64 unsigned 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 #endif 72 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 73 } 74