File indexing completed on 2025-01-18 09:53:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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:
0026
0027 T* backup_;
0028
0029 public:
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:
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:
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
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 }}
0093 }
0094
0095 #endif