1 //-----------------------------------------------------------------------------
2 // boost variant/recursive_wrapper.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
6 // Copyright (c) 2002-2003
7 // Eric Friedman, Itay Maman
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
14 #define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
16 #include <boost/variant/recursive_wrapper_fwd.hpp>
17 #include <boost/variant/detail/move.hpp>
18 #include <boost/checked_delete.hpp>
22 //////////////////////////////////////////////////////////////////////////
23 // class template recursive_wrapper
25 // See docs and recursive_wrapper_fwd.hpp for more information.
29 class recursive_wrapper
35 private: // representation
44 recursive_wrapper(const recursive_wrapper& operand);
45 recursive_wrapper(const T& operand);
47 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
48 recursive_wrapper(recursive_wrapper&& operand);
49 recursive_wrapper(T&& operand);
52 private: // helpers, for modifiers (below)
54 void assign(const T& rhs);
58 recursive_wrapper& operator=(const recursive_wrapper& rhs)
64 recursive_wrapper& operator=(const T& rhs)
70 void swap(recursive_wrapper& operand) BOOST_NOEXCEPT
78 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
79 recursive_wrapper& operator=(recursive_wrapper&& rhs) BOOST_NOEXCEPT
85 recursive_wrapper& operator=(T&& rhs)
87 get() = detail::variant::move(rhs);
94 T& get() { return *get_pointer(); }
95 const T& get() const { return *get_pointer(); }
97 T* get_pointer() { return p_; }
98 const T* get_pointer() const { return p_; }
102 template <typename T>
103 recursive_wrapper<T>::~recursive_wrapper()
105 boost::checked_delete(p_);
108 template <typename T>
109 recursive_wrapper<T>::recursive_wrapper()
114 template <typename T>
115 recursive_wrapper<T>::recursive_wrapper(const recursive_wrapper& operand)
116 : p_(new T( operand.get() ))
120 template <typename T>
121 recursive_wrapper<T>::recursive_wrapper(const T& operand)
126 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
127 template <typename T>
128 recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
129 : p_(new T( detail::variant::move(operand.get()) ))
133 template <typename T>
134 recursive_wrapper<T>::recursive_wrapper(T&& operand)
135 : p_(new T( detail::variant::move(operand) ))
140 template <typename T>
141 void recursive_wrapper<T>::assign(const T& rhs)
146 // function template swap
148 // Swaps two recursive_wrapper<T> objects of the same type T.
150 template <typename T>
151 inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) BOOST_NOEXCEPT
158 #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_HPP