doc_move_inserter.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_inserter_example
  13. #include <boost/container/list.hpp>
  14. #include "movable.hpp"
  15. #include <cassert>
  16. #include <algorithm>
  17. using namespace ::boost::container;
  18. typedef list<movable> list_t;
  19. typedef list_t::iterator l_iterator;
  20. template<class MoveInsertIterator>
  21. void test_move_inserter(list_t &l2, MoveInsertIterator mit)
  22. {
  23. //Create a list with 10 default constructed objects
  24. list<movable> l(10);
  25. assert(!l.begin()->moved());
  26. l2.clear();
  27. //Move insert into l2 containers
  28. std::copy(l.begin(), l.end(), mit);
  29. //Check size and status
  30. assert(l2.size() == l.size());
  31. assert(l.begin()->moved());
  32. assert(!l2.begin()->moved());
  33. }
  34. int main()
  35. {
  36. list_t l2;
  37. test_move_inserter(l2, boost::back_move_inserter(l2));
  38. test_move_inserter(l2, boost::front_move_inserter(l2));
  39. test_move_inserter(l2, boost::move_inserter(l2, l2.end()));
  40. return 0;
  41. }
  42. //]
  43. #include <boost/move/detail/config_end.hpp>