move_iterator.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #include <boost/move/iterator.hpp>
  13. #include <boost/container/vector.hpp>
  14. #include <boost/core/lightweight_test.hpp>
  15. #include "../example/movable.hpp"
  16. int main()
  17. {
  18. namespace bc = ::boost::container;
  19. //Default construct 10 movable objects
  20. bc::vector<movable> v(10);
  21. //Test default constructed value
  22. BOOST_TEST(!v[0].moved());
  23. //Move values
  24. bc::vector<movable> v2
  25. (boost::make_move_iterator(v.begin()), boost::make_move_iterator(v.end()));
  26. //Test values have been moved
  27. BOOST_TEST(v[0].moved());
  28. BOOST_TEST(v2.size() == 10);
  29. //Move again
  30. v.assign(boost::make_move_iterator(v2.begin()), boost::make_move_iterator(v2.end()));
  31. //Test values have been moved
  32. BOOST_TEST(v2[0].moved());
  33. BOOST_TEST(!v[0].moved());
  34. return ::boost::report_errors();
  35. }
  36. #include <boost/move/detail/config_end.hpp>