Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:10

0001 //-----------------------------------------------------------------------------
0002 // boost variant/recursive_wrapper.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2002-2003
0007 // Eric Friedman, Itay Maman
0008 //
0009 // Distributed under the Boost Software License, Version 1.0. (See
0010 // accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
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 // class template recursive_wrapper
0024 //
0025 // See docs and recursive_wrapper_fwd.hpp for more information.
0026 //
0027 
0028 template <typename T>
0029 class recursive_wrapper
0030 {
0031 public: // typedefs
0032 
0033     typedef T type;
0034 
0035 private: // representation
0036 
0037     T* p_;
0038 
0039 public: // structors
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: // helpers, for modifiers (below)
0053 
0054     void assign(const T& rhs);
0055 
0056 public: // modifiers
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: // queries
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 // function template swap
0147 //
0148 // Swaps two recursive_wrapper<T> objects of the same type T.
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 } // namespace boost
0157 
0158 #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_HPP