source: NonGTP/Boost/boost/variant/detail/backup_holder.hpp @ 857

Revision 857, 1.9 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]1//-----------------------------------------------------------------------------
2// boost variant/detail/backup_holder.hpp header file
3// See http://www.boost.org for updates, documentation, and revision history.
4//-----------------------------------------------------------------------------
5//
6// Copyright (c) 2003
7// Eric Friedman
8//
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)
12
13#ifndef BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
14#define BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
15
16#include "boost/assert.hpp"
17
18namespace boost {
19namespace detail { namespace variant {
20
21template <typename T>
22class backup_holder
23{
24private: // representation
25
26    T* backup_;
27
28public: // structors
29
30    ~backup_holder()
31    {
32        delete backup_;
33    }
34
35    explicit backup_holder(T* backup)
36        : backup_(backup)
37    {
38    }
39
40    backup_holder(const backup_holder&);
41
42public: // modifiers
43
44    backup_holder& operator=(const backup_holder& rhs)
45    {
46        *backup_ = rhs.get();
47        return *this;
48    }
49
50    backup_holder& operator=(const T& rhs)
51    {
52        *backup_ = rhs;
53        return *this;
54    }
55
56    void swap(backup_holder& rhs)
57    {
58        T* tmp = rhs.backup_;
59        rhs.backup_ = this->backup_;
60        this->backup_ = tmp;
61    }
62
63public: // queries
64
65    T& get()
66    {
67        return *backup_;
68    }
69
70    const T& get() const
71    {
72        return *backup_;
73    }
74
75};
76
77template <typename T>
78backup_holder<T>::backup_holder(const backup_holder&)
79    : backup_(0)
80{
81    // not intended for copy, but do not want to prohibit syntactically
82    BOOST_ASSERT(false);
83}
84
85template <typename T>
86void swap(backup_holder<T>& lhs, backup_holder<T>& rhs)
87{
88    lhs.swap(rhs);
89}
90
91}} // namespace detail::variant
92} // namespace boost
93
94#endif // BOOST_VARIANT_DETAIL_BACKUP_HOLDER_HPP
Note: See TracBrowser for help on using the repository browser.