copymovable.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef BOOST_MOVE_TEST_COPYMOVABLE_HPP
  12. #define BOOST_MOVE_TEST_COPYMOVABLE_HPP
  13. #include <boost/move/detail/config_begin.hpp>
  14. //[copy_movable_definition
  15. //header file "copymovable.hpp"
  16. #include <boost/move/core.hpp>
  17. //A copy_movable class
  18. class copy_movable
  19. {
  20. BOOST_COPYABLE_AND_MOVABLE(copy_movable)
  21. int value_;
  22. public:
  23. copy_movable() : value_(1){}
  24. //Move constructor and assignment
  25. copy_movable(BOOST_RV_REF(copy_movable) m)
  26. { value_ = m.value_; m.value_ = 0; }
  27. copy_movable(const copy_movable &m)
  28. { value_ = m.value_; }
  29. copy_movable & operator=(BOOST_RV_REF(copy_movable) m)
  30. { value_ = m.value_; m.value_ = 0; return *this; }
  31. copy_movable & operator=(BOOST_COPY_ASSIGN_REF(copy_movable) m)
  32. { value_ = m.value_; return *this; }
  33. bool moved() const //Observer
  34. { return value_ == 0; }
  35. };
  36. //A copyable-only class
  37. class copyable
  38. {};
  39. //A copyable-only class
  40. class non_copy_movable
  41. {
  42. public:
  43. non_copy_movable(){}
  44. private:
  45. non_copy_movable(const non_copy_movable&);
  46. non_copy_movable& operator=(const non_copy_movable&);
  47. };
  48. //]
  49. #include <boost/move/detail/config_end.hpp>
  50. #endif //BOOST_MOVE_TEST_COPYMOVABLE_HPP