GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / arm-brcm-linux-uclibcgnueabi / include / c++ / 4.5.3 / backward / auto_ptr.h
blobd60bad3d088596ad0c493cff3ef478fb59bf8c03
1 // auto_ptr implementation -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file backward/auto_ptr.h
26 * This is an internal header file, included by other library headers.
27 * You should not attempt to use it directly.
30 #ifndef _BACKWARD_AUTO_PTR_H
31 #define _BACKWARD_AUTO_PTR_H 1
33 #include <bits/c++config.h>
34 #include <debug/debug.h>
36 _GLIBCXX_BEGIN_NAMESPACE(std)
38 /**
39 * A wrapper class to provide auto_ptr with reference semantics.
40 * For example, an auto_ptr can be assigned (or constructed from)
41 * the result of a function which returns an auto_ptr by value.
43 * All the auto_ptr_ref stuff should happen behind the scenes.
45 template<typename _Tp1>
46 struct auto_ptr_ref
48 _Tp1* _M_ptr;
50 explicit
51 auto_ptr_ref(_Tp1* __p): _M_ptr(__p) { }
52 } _GLIBCXX_DEPRECATED_ATTR;
55 /**
56 * @brief A simple smart pointer providing strict ownership semantics.
58 * The Standard says:
59 * <pre>
60 * An @c auto_ptr owns the object it holds a pointer to. Copying
61 * an @c auto_ptr copies the pointer and transfers ownership to the
62 * destination. If more than one @c auto_ptr owns the same object
63 * at the same time the behavior of the program is undefined.
65 * The uses of @c auto_ptr include providing temporary
66 * exception-safety for dynamically allocated memory, passing
67 * ownership of dynamically allocated memory to a function, and
68 * returning dynamically allocated memory from a function. @c
69 * auto_ptr does not meet the CopyConstructible and Assignable
70 * requirements for Standard Library <a
71 * href="tables.html#65">container</a> elements and thus
72 * instantiating a Standard Library container with an @c auto_ptr
73 * results in undefined behavior.
74 * </pre>
75 * Quoted from [20.4.5]/3.
77 * Good examples of what can and cannot be done with auto_ptr can
78 * be found in the libstdc++ testsuite.
80 * _GLIBCXX_RESOLVE_LIB_DEFECTS
81 * 127. auto_ptr<> conversion issues
82 * These resolutions have all been incorporated.
84 template<typename _Tp>
85 class auto_ptr
87 private:
88 _Tp* _M_ptr;
90 public:
91 /// The pointed-to type.
92 typedef _Tp element_type;
94 /**
95 * @brief An %auto_ptr is usually constructed from a raw pointer.
96 * @param p A pointer (defaults to NULL).
98 * This object now @e owns the object pointed to by @a p.
100 explicit
101 auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { }
104 * @brief An %auto_ptr can be constructed from another %auto_ptr.
105 * @param a Another %auto_ptr of the same type.
107 * This object now @e owns the object previously owned by @a a,
108 * which has given up ownership.
110 auto_ptr(auto_ptr& __a) throw() : _M_ptr(__a.release()) { }
113 * @brief An %auto_ptr can be constructed from another %auto_ptr.
114 * @param a Another %auto_ptr of a different but related type.
116 * A pointer-to-Tp1 must be convertible to a
117 * pointer-to-Tp/element_type.
119 * This object now @e owns the object previously owned by @a a,
120 * which has given up ownership.
122 template<typename _Tp1>
123 auto_ptr(auto_ptr<_Tp1>& __a) throw() : _M_ptr(__a.release()) { }
126 * @brief %auto_ptr assignment operator.
127 * @param a Another %auto_ptr of the same type.
129 * This object now @e owns the object previously owned by @a a,
130 * which has given up ownership. The object that this one @e
131 * used to own and track has been deleted.
133 auto_ptr&
134 operator=(auto_ptr& __a) throw()
136 reset(__a.release());
137 return *this;
141 * @brief %auto_ptr assignment operator.
142 * @param a Another %auto_ptr of a different but related type.
144 * A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.
146 * This object now @e owns the object previously owned by @a a,
147 * which has given up ownership. The object that this one @e
148 * used to own and track has been deleted.
150 template<typename _Tp1>
151 auto_ptr&
152 operator=(auto_ptr<_Tp1>& __a) throw()
154 reset(__a.release());
155 return *this;
159 * When the %auto_ptr goes out of scope, the object it owns is
160 * deleted. If it no longer owns anything (i.e., @c get() is
161 * @c NULL), then this has no effect.
163 * The C++ standard says there is supposed to be an empty throw
164 * specification here, but omitting it is standard conforming. Its
165 * presence can be detected only if _Tp::~_Tp() throws, but this is
166 * prohibited. [17.4.3.6]/2
168 ~auto_ptr() { delete _M_ptr; }
171 * @brief Smart pointer dereferencing.
173 * If this %auto_ptr no longer owns anything, then this
174 * operation will crash. (For a smart pointer, <em>no longer owns
175 * anything</em> is the same as being a null pointer, and you know
176 * what happens when you dereference one of those...)
178 element_type&
179 operator*() const throw()
181 _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
182 return *_M_ptr;
186 * @brief Smart pointer dereferencing.
188 * This returns the pointer itself, which the language then will
189 * automatically cause to be dereferenced.
191 element_type*
192 operator->() const throw()
194 _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
195 return _M_ptr;
199 * @brief Bypassing the smart pointer.
200 * @return The raw pointer being managed.
202 * You can get a copy of the pointer that this object owns, for
203 * situations such as passing to a function which only accepts
204 * a raw pointer.
206 * @note This %auto_ptr still owns the memory.
208 element_type*
209 get() const throw() { return _M_ptr; }
212 * @brief Bypassing the smart pointer.
213 * @return The raw pointer being managed.
215 * You can get a copy of the pointer that this object owns, for
216 * situations such as passing to a function which only accepts
217 * a raw pointer.
219 * @note This %auto_ptr no longer owns the memory. When this object
220 * goes out of scope, nothing will happen.
222 element_type*
223 release() throw()
225 element_type* __tmp = _M_ptr;
226 _M_ptr = 0;
227 return __tmp;
231 * @brief Forcibly deletes the managed object.
232 * @param p A pointer (defaults to NULL).
234 * This object now @e owns the object pointed to by @a p. The
235 * previous object has been deleted.
237 void
238 reset(element_type* __p = 0) throw()
240 if (__p != _M_ptr)
242 delete _M_ptr;
243 _M_ptr = __p;
247 /**
248 * @brief Automatic conversions
250 * These operations convert an %auto_ptr into and from an auto_ptr_ref
251 * automatically as needed. This allows constructs such as
252 * @code
253 * auto_ptr<Derived> func_returning_auto_ptr(.....);
254 * ...
255 * auto_ptr<Base> ptr = func_returning_auto_ptr(.....);
256 * @endcode
258 auto_ptr(auto_ptr_ref<element_type> __ref) throw()
259 : _M_ptr(__ref._M_ptr) { }
261 auto_ptr&
262 operator=(auto_ptr_ref<element_type> __ref) throw()
264 if (__ref._M_ptr != this->get())
266 delete _M_ptr;
267 _M_ptr = __ref._M_ptr;
269 return *this;
272 template<typename _Tp1>
273 operator auto_ptr_ref<_Tp1>() throw()
274 { return auto_ptr_ref<_Tp1>(this->release()); }
276 template<typename _Tp1>
277 operator auto_ptr<_Tp1>() throw()
278 { return auto_ptr<_Tp1>(this->release()); }
279 } _GLIBCXX_DEPRECATED_ATTR;
281 // _GLIBCXX_RESOLVE_LIB_DEFECTS
282 // 541. shared_ptr template assignment and void
283 template<>
284 class auto_ptr<void>
286 public:
287 typedef void element_type;
288 } _GLIBCXX_DEPRECATED_ATTR;
290 _GLIBCXX_END_NAMESPACE
292 #endif /* _BACKWARD_AUTO_PTR_H */