doc_move_algorithms.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_algorithms_example
  13. #include "movable.hpp"
  14. #include <boost/move/algorithm.hpp>
  15. #include <cassert>
  16. #include <boost/aligned_storage.hpp>
  17. int main()
  18. {
  19. const std::size_t ArraySize = 10;
  20. movable movable_array[ArraySize];
  21. movable movable_array2[ArraySize];
  22. //move
  23. boost::move(&movable_array2[0], &movable_array2[ArraySize], &movable_array[0]);
  24. assert(movable_array2[0].moved());
  25. assert(!movable_array[0].moved());
  26. //move backward
  27. boost::move_backward(&movable_array[0], &movable_array[ArraySize], &movable_array2[ArraySize]);
  28. assert(movable_array[0].moved());
  29. assert(!movable_array2[0].moved());
  30. //uninitialized_move
  31. boost::aligned_storage< sizeof(movable)*ArraySize
  32. , boost::alignment_of<movable>::value>::type storage;
  33. movable *raw_movable = static_cast<movable*>(static_cast<void*>(&storage));
  34. boost::uninitialized_move(&movable_array2[0], &movable_array2[ArraySize], raw_movable);
  35. assert(movable_array2[0].moved());
  36. assert(!raw_movable[0].moved());
  37. return 0;
  38. }
  39. //]
  40. #include <boost/move/detail/config_end.hpp>