Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 #ifndef BOOST_SCOPED_PTR_HPP_INCLUDED
2 #define BOOST_SCOPED_PTR_HPP_INCLUDED
4 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
5 // Copyright (c) 2001, 2002 Peter Dimov
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 // http://www.boost.org/libs/smart_ptr/scoped_ptr.htm
14 #include <boost/assert.hpp>
15 #include <boost/checked_delete.hpp>
16 #include <boost/detail/workaround.hpp>
18 #ifndef BOOST_NO_AUTO_PTR
19 # include <memory> // for std::auto_ptr
27 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
29 void sp_scalar_constructor_hook(void * p);
30 void sp_scalar_destructor_hook(void * p);
34 // scoped_ptr mimics a built-in pointer except that it guarantees deletion
35 // of the object pointed to, either on destruction of the scoped_ptr or via
36 // an explicit reset(). scoped_ptr is a simple solution for simple needs;
37 // use shared_ptr or std::auto_ptr if your needs are more complex.
39 template<class T> class scoped_ptr // noncopyable
45 scoped_ptr(scoped_ptr const &);
46 scoped_ptr & operator=(scoped_ptr const &);
48 typedef scoped_ptr<T> this_type;
52 typedef T element_type;
54 explicit scoped_ptr(T * p = 0): ptr(p) // never throws
56 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
57 boost::sp_scalar_constructor_hook(ptr);
61 #ifndef BOOST_NO_AUTO_PTR
63 explicit scoped_ptr(std::auto_ptr<T> p): ptr(p.release()) // never throws
65 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
66 boost::sp_scalar_constructor_hook(ptr);
72 ~scoped_ptr() // never throws
74 #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
75 boost::sp_scalar_destructor_hook(ptr);
77 boost::checked_delete(ptr);
80 void reset(T * p = 0) // never throws
82 BOOST_ASSERT(p == 0 || p != ptr); // catch self-reset errors
83 this_type(p).swap(*this);
86 T & operator*() const // never throws
88 BOOST_ASSERT(ptr != 0);
92 T * operator->() const // never throws
94 BOOST_ASSERT(ptr != 0);
98 T * get() const // never throws
103 // implicit conversion to "bool"
105 #if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
107 operator bool () const
112 #elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
113 typedef T * (this_type::*unspecified_bool_type)() const;
115 operator unspecified_bool_type() const // never throws
117 return ptr == 0? 0: &this_type::get;
121 typedef T * this_type::*unspecified_bool_type;
123 operator unspecified_bool_type() const // never throws
125 return ptr == 0? 0: &this_type::ptr;
130 bool operator! () const // never throws
135 void swap(scoped_ptr & b) // never throws
143 template<class T> inline void swap(scoped_ptr<T> & a, scoped_ptr<T> & b) // never throws
148 // get_pointer(p) is a generic way to say p.get()
150 template<class T> inline T * get_pointer(scoped_ptr<T> const & p)
157 #endif // #ifndef BOOST_SCOPED_PTR_HPP_INCLUDED