movable.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_MOVABLE_HPP
  12. #define BOOST_MOVE_TEST_MOVABLE_HPP
  13. #include <boost/move/detail/config_begin.hpp>
  14. //[movable_definition
  15. //header file "movable.hpp"
  16. #include <boost/move/core.hpp>
  17. #include <boost/move/traits.hpp>
  18. //A movable class
  19. class movable
  20. {
  21. BOOST_MOVABLE_BUT_NOT_COPYABLE(movable)
  22. int value_;
  23. public:
  24. movable() : value_(1){}
  25. //Move constructor and assignment
  26. movable(BOOST_RV_REF(movable) m)
  27. { value_ = m.value_; m.value_ = 0; }
  28. movable & operator=(BOOST_RV_REF(movable) m)
  29. { value_ = m.value_; m.value_ = 0; return *this; }
  30. bool moved() const //Observer
  31. { return !value_; }
  32. int value() const //Observer
  33. { return value_; }
  34. };
  35. namespace boost{
  36. template<>
  37. struct has_nothrow_move<movable>
  38. {
  39. static const bool value = true;
  40. };
  41. } //namespace boost{
  42. //]
  43. #include <boost/move/detail/config_end.hpp>
  44. #endif //BOOST_MOVE_TEST_MOVABLE_HPP