Chris@16
|
1 //-----------------------------------------------------------------------------
|
Chris@16
|
2 // boost variant/recursive_wrapper.hpp header file
|
Chris@16
|
3 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
4 //-----------------------------------------------------------------------------
|
Chris@16
|
5 //
|
Chris@16
|
6 // Copyright (c) 2002-2003
|
Chris@16
|
7 // Eric Friedman, Itay Maman
|
Chris@16
|
8 //
|
Chris@16
|
9 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
10 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
11 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|
Chris@16
|
14 #define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include "boost/variant/recursive_wrapper_fwd.hpp"
|
Chris@16
|
17 #include "boost/variant/detail/move.hpp"
|
Chris@16
|
18 #include "boost/checked_delete.hpp"
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost {
|
Chris@16
|
21
|
Chris@16
|
22 //////////////////////////////////////////////////////////////////////////
|
Chris@16
|
23 // class template recursive_wrapper
|
Chris@16
|
24 //
|
Chris@16
|
25 // See docs and recursive_wrapper_fwd.hpp for more information.
|
Chris@16
|
26 //
|
Chris@16
|
27
|
Chris@16
|
28 template <typename T>
|
Chris@16
|
29 class recursive_wrapper
|
Chris@16
|
30 {
|
Chris@16
|
31 public: // typedefs
|
Chris@16
|
32
|
Chris@16
|
33 typedef T type;
|
Chris@16
|
34
|
Chris@16
|
35 private: // representation
|
Chris@16
|
36
|
Chris@16
|
37 T* p_;
|
Chris@16
|
38
|
Chris@16
|
39 public: // structors
|
Chris@16
|
40
|
Chris@16
|
41 ~recursive_wrapper();
|
Chris@16
|
42 recursive_wrapper();
|
Chris@16
|
43
|
Chris@16
|
44 recursive_wrapper(const recursive_wrapper& operand);
|
Chris@16
|
45 recursive_wrapper(const T& operand);
|
Chris@16
|
46
|
Chris@16
|
47 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
48 recursive_wrapper(recursive_wrapper&& operand);
|
Chris@16
|
49 recursive_wrapper(T&& operand);
|
Chris@16
|
50 #endif
|
Chris@16
|
51
|
Chris@16
|
52 private: // helpers, for modifiers (below)
|
Chris@16
|
53
|
Chris@16
|
54 void assign(const T& rhs);
|
Chris@16
|
55
|
Chris@16
|
56 public: // modifiers
|
Chris@16
|
57
|
Chris@16
|
58 recursive_wrapper& operator=(const recursive_wrapper& rhs)
|
Chris@16
|
59 {
|
Chris@16
|
60 assign( rhs.get() );
|
Chris@16
|
61 return *this;
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 recursive_wrapper& operator=(const T& rhs)
|
Chris@16
|
65 {
|
Chris@16
|
66 assign( rhs );
|
Chris@16
|
67 return *this;
|
Chris@16
|
68 }
|
Chris@16
|
69
|
Chris@16
|
70 void swap(recursive_wrapper& operand) BOOST_NOEXCEPT
|
Chris@16
|
71 {
|
Chris@16
|
72 T* temp = operand.p_;
|
Chris@16
|
73 operand.p_ = p_;
|
Chris@16
|
74 p_ = temp;
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77
|
Chris@16
|
78 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
79 recursive_wrapper& operator=(recursive_wrapper&& rhs) BOOST_NOEXCEPT
|
Chris@16
|
80 {
|
Chris@16
|
81 swap(rhs);
|
Chris@16
|
82 return *this;
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 recursive_wrapper& operator=(T&& rhs)
|
Chris@16
|
86 {
|
Chris@16
|
87 get() = detail::variant::move(rhs);
|
Chris@16
|
88 return *this;
|
Chris@16
|
89 }
|
Chris@16
|
90 #endif
|
Chris@16
|
91
|
Chris@16
|
92 public: // queries
|
Chris@16
|
93
|
Chris@16
|
94 T& get() { return *get_pointer(); }
|
Chris@16
|
95 const T& get() const { return *get_pointer(); }
|
Chris@16
|
96
|
Chris@16
|
97 T* get_pointer() { return p_; }
|
Chris@16
|
98 const T* get_pointer() const { return p_; }
|
Chris@16
|
99
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102 template <typename T>
|
Chris@16
|
103 recursive_wrapper<T>::~recursive_wrapper()
|
Chris@16
|
104 {
|
Chris@16
|
105 boost::checked_delete(p_);
|
Chris@16
|
106 }
|
Chris@16
|
107
|
Chris@16
|
108 template <typename T>
|
Chris@16
|
109 recursive_wrapper<T>::recursive_wrapper()
|
Chris@16
|
110 : p_(new T)
|
Chris@16
|
111 {
|
Chris@16
|
112 }
|
Chris@16
|
113
|
Chris@16
|
114 template <typename T>
|
Chris@16
|
115 recursive_wrapper<T>::recursive_wrapper(const recursive_wrapper& operand)
|
Chris@16
|
116 : p_(new T( operand.get() ))
|
Chris@16
|
117 {
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 template <typename T>
|
Chris@16
|
121 recursive_wrapper<T>::recursive_wrapper(const T& operand)
|
Chris@16
|
122 : p_(new T(operand))
|
Chris@16
|
123 {
|
Chris@16
|
124 }
|
Chris@16
|
125
|
Chris@16
|
126 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
127 template <typename T>
|
Chris@16
|
128 recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
|
Chris@16
|
129 : p_(new T( detail::variant::move(operand.get()) ))
|
Chris@16
|
130 {
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 template <typename T>
|
Chris@16
|
134 recursive_wrapper<T>::recursive_wrapper(T&& operand)
|
Chris@16
|
135 : p_(new T( detail::variant::move(operand) ))
|
Chris@16
|
136 {
|
Chris@16
|
137 }
|
Chris@16
|
138 #endif
|
Chris@16
|
139
|
Chris@16
|
140 template <typename T>
|
Chris@16
|
141 void recursive_wrapper<T>::assign(const T& rhs)
|
Chris@16
|
142 {
|
Chris@16
|
143 this->get() = rhs;
|
Chris@16
|
144 }
|
Chris@16
|
145
|
Chris@16
|
146 // function template swap
|
Chris@16
|
147 //
|
Chris@16
|
148 // Swaps two recursive_wrapper<T> objects of the same type T.
|
Chris@16
|
149 //
|
Chris@16
|
150 template <typename T>
|
Chris@16
|
151 inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) BOOST_NOEXCEPT
|
Chris@16
|
152 {
|
Chris@16
|
153 lhs.swap(rhs);
|
Chris@16
|
154 }
|
Chris@16
|
155
|
Chris@16
|
156 } // namespace boost
|
Chris@16
|
157
|
Chris@16
|
158 #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
|