move_algorithm.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/algorithm.hpp>
  13. #include <boost/container/vector.hpp>
  14. #include "../example/movable.hpp"
  15. int main()
  16. {
  17. namespace bc = ::boost::container;
  18. //Default construct 10 movable objects
  19. bc::vector<movable> v(10);
  20. bc::vector<movable> v2(10);
  21. //Move to v2
  22. boost::move(v.begin(), v.end(), v2.begin());
  23. //Test values have been moved
  24. if(!v[0].moved()){
  25. return 1;
  26. }
  27. if(v2.size() != 10){
  28. return 1;
  29. }
  30. if(v2[0].moved()){
  31. return 1;
  32. }
  33. //Move to v again
  34. boost::move_backward(v2.begin(), v2.end(), v.end());
  35. //Test values have been moved
  36. if(!v2[1].moved()){
  37. return 1;
  38. }
  39. if(v.size() != 10){
  40. return 1;
  41. }
  42. if(v[1].moved()){
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. #include <boost/move/detail/config_end.hpp>