Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / move / example / movable.hpp
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
14 #include <boost/move/detail/config_begin.hpp>
15
16 //[movable_definition 
17 //header file "movable.hpp"
18 #include <boost/move/core.hpp>
19 #include <boost/move/traits.hpp>
20
21 //A movable class
22 class movable
23 {
24    BOOST_MOVABLE_BUT_NOT_COPYABLE(movable)
25    int value_;
26
27    public:
28    movable() : value_(1){}
29
30    //Move constructor and assignment
31    movable(BOOST_RV_REF(movable) m)
32    {  value_ = m.value_;   m.value_ = 0;  }
33
34    movable & operator=(BOOST_RV_REF(movable) m)
35    {  value_ = m.value_;   m.value_ = 0;  return *this;  }
36
37    bool moved() const //Observer
38    {  return !value_; }
39
40    int value() const //Observer
41    {  return value_; }
42 };
43
44 namespace boost{
45
46 template<>
47 struct has_nothrow_move<movable>
48 {
49    static const bool value = true;
50 };
51
52 }  //namespace boost{
53 //]
54
55 #include <boost/move/detail/config_end.hpp>
56
57 #endif //BOOST_MOVE_TEST_MOVABLE_HPP