1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright David Abrahams, Vicente Botet, 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 #include <boost/move/detail/config_begin.hpp> 12 // move 13 #include <boost/move/algorithm.hpp> 14 #include <boost/move/iterator.hpp> 15 // container 16 #include <boost/container/deque.hpp> 17 #include <boost/container/list.hpp> 18 #include <boost/container/stable_vector.hpp> 19 #include "../example/movable.hpp" 20 21 template<class Container> move_test()22int move_test() 23 { 24 bool use_move_iterator = false; 25 bool done = false; 26 while(!done){ 27 //Default construct 10 movable objects 28 Container v(10); 29 30 //Test default constructed value 31 if(v.begin()->moved()){ 32 return 1; 33 } 34 35 //Move values 36 Container v2; 37 if(use_move_iterator){ 38 ::boost::copy_or_move( boost::make_move_iterator(v.begin()) 39 , boost::make_move_iterator(v.end()) 40 , boost::back_move_inserter(v2)); 41 } 42 else{ 43 std::copy(v.begin(), v.end(), boost::back_move_inserter(v2)); 44 } 45 46 //Test values have been moved 47 if(!v.begin()->moved()){ 48 return 1; 49 } 50 51 if(v2.size() != 10){ 52 return 1; 53 } 54 55 if(v2.begin()->moved()){ 56 return 1; 57 } 58 done = use_move_iterator; 59 use_move_iterator = true; 60 } 61 return 0; 62 } 63 main()64int main() 65 { 66 namespace bc = ::boost::container; 67 68 if(move_test< bc::vector<movable> >()){ 69 return 1; 70 } 71 if(move_test< bc::list<movable> >()){ 72 return 1; 73 } 74 if(move_test< bc::stable_vector<movable> >()){ 75 return 1; 76 } 77 return 0; 78 } 79 80 #include <boost/move/detail/config_end.hpp> 81