1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2009. 4 // Distributed under the Boost Software License, Version 1.0. 5 // (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // See http://www.boost.org/libs/move for documentation. 9 // 10 ////////////////////////////////////////////////////////////////////////////// 11 12 //[move_inserter_example 13 #include <boost/container/list.hpp> 14 #include "movable.hpp" 15 #include <cassert> 16 #include <algorithm> 17 18 using namespace ::boost::container; 19 20 typedef list<movable> list_t; 21 typedef list_t::iterator l_iterator; 22 23 template<class MoveInsertIterator> test_move_inserter(list_t & l2,MoveInsertIterator mit)24void test_move_inserter(list_t &l2, MoveInsertIterator mit) 25 { 26 //Create a list with 10 default constructed objects 27 list<movable> l(10); 28 assert(!l.begin()->moved()); 29 l2.clear(); 30 31 //Move insert into l2 containers 32 std::copy(l.begin(), l.end(), mit); 33 34 //Check size and status 35 assert(l2.size() == l.size()); 36 assert(l.begin()->moved()); 37 assert(!l2.begin()->moved()); 38 } 39 main()40int main() 41 { 42 list_t l2; 43 test_move_inserter(l2, boost::back_move_inserter(l2)); 44 test_move_inserter(l2, boost::front_move_inserter(l2)); 45 test_move_inserter(l2, boost::move_inserter(l2, l2.end())); 46 return 0; 47 } 48 //] 49