movable.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Boost.Geometry.Index varray
  2. // Unit Test
  3. // Copyright (c) 2009 Ion Gaztanaga
  4. // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
  5. // Use, modification and distribution is subject to the Boost Software License,
  6. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP
  9. #define BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP
  10. //[movable_definition
  11. //header file "movable.hpp"
  12. #include <boost/move/move.hpp>
  13. //A movable class
  14. class movable
  15. {
  16. BOOST_MOVABLE_BUT_NOT_COPYABLE(movable)
  17. int value_;
  18. public:
  19. movable() : value_(1){}
  20. //Move constructor and assignment
  21. movable(BOOST_RV_REF(movable) m)
  22. { value_ = m.value_; m.value_ = 0; }
  23. movable & operator=(BOOST_RV_REF(movable) m)
  24. { value_ = m.value_; m.value_ = 0; return *this; }
  25. bool moved() const //Observer
  26. { return value_ == 0; }
  27. };
  28. class copy_movable
  29. {
  30. BOOST_COPYABLE_AND_MOVABLE(copy_movable)
  31. size_t value_;
  32. public:
  33. copy_movable(size_t value = 1) : value_(value){}
  34. //Move constructor and assignment
  35. copy_movable(BOOST_RV_REF(copy_movable) m)
  36. { value_ = m.value_; m.value_ = 0; }
  37. copy_movable(const copy_movable &m)
  38. { value_ = m.value_; }
  39. copy_movable & operator=(BOOST_RV_REF(copy_movable) m)
  40. { value_ = m.value_; m.value_ = 0; return *this; }
  41. copy_movable & operator=(BOOST_COPY_ASSIGN_REF(copy_movable) m)
  42. { value_ = m.value_; return *this; }
  43. bool moved() const //Observer
  44. { return value_ == 0; }
  45. bool operator==(const copy_movable& m) const
  46. { return value_ == m.value_; }
  47. };
  48. struct copy_movable_wrapper
  49. {
  50. copy_movable cm;
  51. };
  52. copy_movable produce()
  53. { return copy_movable(); }
  54. namespace boost{
  55. template<>
  56. struct has_nothrow_move<movable>
  57. {
  58. static const bool value = true;
  59. };
  60. template<>
  61. struct has_nothrow_move<copy_movable>
  62. {
  63. static const bool value = true;
  64. };
  65. } //namespace boost{
  66. //]
  67. #endif //BOOST_GEOMETRY_INDEX_TEST_MOVABLE_HPP