File indexing completed on 2025-01-30 10:02:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
0014 #define BOOST_VARIANT_RECURSIVE_WRAPPER_HPP
0015
0016 #include <boost/variant/recursive_wrapper_fwd.hpp>
0017 #include <boost/variant/detail/move.hpp>
0018 #include <boost/core/checked_delete.hpp>
0019
0020 namespace boost {
0021
0022
0023
0024
0025
0026
0027
0028 template <typename T>
0029 class recursive_wrapper
0030 {
0031 public:
0032
0033 typedef T type;
0034
0035 private:
0036
0037 T* p_;
0038
0039 public:
0040
0041 ~recursive_wrapper();
0042 recursive_wrapper();
0043
0044 recursive_wrapper(const recursive_wrapper& operand);
0045 recursive_wrapper(const T& operand);
0046
0047 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0048 recursive_wrapper(recursive_wrapper&& operand);
0049 recursive_wrapper(T&& operand);
0050 #endif
0051
0052 private:
0053
0054 void assign(const T& rhs);
0055
0056 public:
0057
0058 recursive_wrapper& operator=(const recursive_wrapper& rhs)
0059 {
0060 assign( rhs.get() );
0061 return *this;
0062 }
0063
0064 recursive_wrapper& operator=(const T& rhs)
0065 {
0066 assign( rhs );
0067 return *this;
0068 }
0069
0070 void swap(recursive_wrapper& operand) BOOST_NOEXCEPT
0071 {
0072 T* temp = operand.p_;
0073 operand.p_ = p_;
0074 p_ = temp;
0075 }
0076
0077
0078 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0079 recursive_wrapper& operator=(recursive_wrapper&& rhs) BOOST_NOEXCEPT
0080 {
0081 swap(rhs);
0082 return *this;
0083 }
0084
0085 recursive_wrapper& operator=(T&& rhs)
0086 {
0087 get() = detail::variant::move(rhs);
0088 return *this;
0089 }
0090 #endif
0091
0092 public:
0093
0094 T& get() { return *get_pointer(); }
0095 const T& get() const { return *get_pointer(); }
0096
0097 T* get_pointer() { return p_; }
0098 const T* get_pointer() const { return p_; }
0099
0100 };
0101
0102 template <typename T>
0103 recursive_wrapper<T>::~recursive_wrapper()
0104 {
0105 boost::checked_delete(p_);
0106 }
0107
0108 template <typename T>
0109 recursive_wrapper<T>::recursive_wrapper()
0110 : p_(new T)
0111 {
0112 }
0113
0114 template <typename T>
0115 recursive_wrapper<T>::recursive_wrapper(const recursive_wrapper& operand)
0116 : p_(new T( operand.get() ))
0117 {
0118 }
0119
0120 template <typename T>
0121 recursive_wrapper<T>::recursive_wrapper(const T& operand)
0122 : p_(new T(operand))
0123 {
0124 }
0125
0126 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0127 template <typename T>
0128 recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
0129 : p_(new T( detail::variant::move(operand.get()) ))
0130 {
0131 }
0132
0133 template <typename T>
0134 recursive_wrapper<T>::recursive_wrapper(T&& operand)
0135 : p_(new T( detail::variant::move(operand) ))
0136 {
0137 }
0138 #endif
0139
0140 template <typename T>
0141 void recursive_wrapper<T>::assign(const T& rhs)
0142 {
0143 this->get() = rhs;
0144 }
0145
0146
0147
0148
0149
0150 template <typename T>
0151 inline void swap(recursive_wrapper<T>& lhs, recursive_wrapper<T>& rhs) BOOST_NOEXCEPT
0152 {
0153 lhs.swap(rhs);
0154 }
0155
0156 }
0157
0158 #endif