back_move_inserter.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. template<class Container>
  21. int move_test()
  22. {
  23. bool use_move_iterator = false;
  24. bool done = false;
  25. while(!done){
  26. //Default construct 10 movable objects
  27. Container v(10);
  28. //Test default constructed value
  29. if(v.begin()->moved()){
  30. return 1;
  31. }
  32. //Move values
  33. Container v2;
  34. if(use_move_iterator){
  35. ::boost::copy_or_move( boost::make_move_iterator(v.begin())
  36. , boost::make_move_iterator(v.end())
  37. , boost::back_move_inserter(v2));
  38. }
  39. else{
  40. std::copy(v.begin(), v.end(), boost::back_move_inserter(v2));
  41. }
  42. //Test values have been moved
  43. if(!v.begin()->moved()){
  44. return 1;
  45. }
  46. if(v2.size() != 10){
  47. return 1;
  48. }
  49. if(v2.begin()->moved()){
  50. return 1;
  51. }
  52. done = use_move_iterator;
  53. use_move_iterator = true;
  54. }
  55. return 0;
  56. }
  57. int main()
  58. {
  59. namespace bc = ::boost::container;
  60. if(move_test< bc::vector<movable> >()){
  61. return 1;
  62. }
  63. if(move_test< bc::list<movable> >()){
  64. return 1;
  65. }
  66. if(move_test< bc::stable_vector<movable> >()){
  67. return 1;
  68. }
  69. return 0;
  70. }
  71. #include <boost/move/detail/config_end.hpp>