doc_move_iterator.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include <boost/move/detail/config_begin.hpp>
  12. //[move_iterator_example
  13. #include <boost/container/vector.hpp>
  14. #include "movable.hpp"
  15. #include <cassert>
  16. int main()
  17. {
  18. using namespace ::boost::container;
  19. //Create a vector with 10 default constructed objects
  20. vector<movable> v(10);
  21. assert(!v[0].moved());
  22. //Move construct all elements in v into v2
  23. vector<movable> v2( boost::make_move_iterator(v.begin())
  24. , boost::make_move_iterator(v.end()));
  25. assert(v[0].moved());
  26. assert(!v2[0].moved());
  27. //Now move assign all elements from in v2 back into v
  28. v.assign( boost::make_move_iterator(v2.begin())
  29. , boost::make_move_iterator(v2.end()));
  30. assert(v2[0].moved());
  31. assert(!v[0].moved());
  32. return 0;
  33. }
  34. //]
  35. #include <boost/move/detail/config_end.hpp>