Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:32

0001 //-----------------------------------------------------------------------------
0002 // boost variant/detail/backup_holder.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2003
0007 // Eric Friedman
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_DETAIL_BACKUP_HOLDER_HPP
0014 #define BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
0015 
0016 #include <boost/config.hpp>
0017 #include <boost/assert.hpp>
0018 
0019 namespace boost {
0020 namespace detail { namespace variant {
0021 
0022 template <typename T>
0023 class backup_holder
0024 {
0025 private: // representation
0026 
0027     T* backup_;
0028 
0029 public: // structors
0030 
0031     ~backup_holder() BOOST_NOEXCEPT
0032     {
0033         delete backup_;
0034     }
0035 
0036     explicit backup_holder(T* backup) BOOST_NOEXCEPT
0037         : backup_(backup)
0038     {
0039     }
0040 
0041     backup_holder(const backup_holder&);
0042 
0043 public: // modifiers
0044 
0045     backup_holder& operator=(const backup_holder& rhs)
0046     {
0047         *backup_ = rhs.get();
0048         return *this;
0049     }
0050 
0051     backup_holder& operator=(const T& rhs)
0052     {
0053         *backup_ = rhs;
0054         return *this;
0055     }
0056 
0057     void swap(backup_holder& rhs) BOOST_NOEXCEPT
0058     {
0059         T* tmp = rhs.backup_;
0060         rhs.backup_ = this->backup_;
0061         this->backup_ = tmp;
0062     }
0063 
0064 public: // queries
0065 
0066     T& get() BOOST_NOEXCEPT
0067     {
0068         return *backup_;
0069     }
0070 
0071     const T& get() const BOOST_NOEXCEPT
0072     {
0073         return *backup_;
0074     }
0075 
0076 };
0077 
0078 template <typename T>
0079 backup_holder<T>::backup_holder(const backup_holder&)
0080     : backup_(0)
0081 {
0082     // not intended for copy, but do not want to prohibit syntactically
0083     BOOST_ASSERT(false);
0084 }
0085 
0086 template <typename T>
0087 void swap(backup_holder<T>& lhs, backup_holder<T>& rhs) BOOST_NOEXCEPT
0088 {
0089     lhs.swap(rhs);
0090 }
0091 
0092 }} // namespace detail::variant
0093 } // namespace boost
0094 
0095 #endif // BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP