Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 #ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED
2 #define BOOST_INTRUSIVE_PTR_HPP_INCLUDED
7 // Copyright (c) 2001, 2002 Peter Dimov
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)
13 // See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
16 #include <boost/config.hpp>
18 #ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
19 # pragma warning(push)
20 # pragma warning(disable:4284) // odd return type for operator->
23 #include <boost/assert.hpp>
24 #include <boost/detail/workaround.hpp>
26 #include <functional> // for std::less
27 #include <iosfwd> // for std::basic_ostream
36 // A smart pointer that uses intrusive reference counting.
38 // Relies on unqualified calls to
40 // void intrusive_ptr_add_ref(T * p);
41 // void intrusive_ptr_release(T * p);
45 // The object is responsible for destroying itself.
48 template<class T> class intrusive_ptr
52 typedef intrusive_ptr this_type;
56 typedef T element_type;
58 intrusive_ptr(): p_(0)
62 intrusive_ptr(T * p, bool add_ref = true): p_(p)
64 if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_);
67 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
69 template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get())
71 if(p_ != 0) intrusive_ptr_add_ref(p_);
76 intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_)
78 if(p_ != 0) intrusive_ptr_add_ref(p_);
83 if(p_ != 0) intrusive_ptr_release(p_);
86 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
88 template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
90 this_type(rhs).swap(*this);
96 intrusive_ptr & operator=(intrusive_ptr const & rhs)
98 this_type(rhs).swap(*this);
102 intrusive_ptr & operator=(T * rhs)
104 this_type(rhs).swap(*this);
113 T & operator*() const
118 T * operator->() const
123 #if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
125 operator bool () const
130 #elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
131 typedef T * (this_type::*unspecified_bool_type)() const;
133 operator unspecified_bool_type() const // never throws
135 return p_ == 0? 0: &this_type::get;
140 typedef T * this_type::*unspecified_bool_type;
142 operator unspecified_bool_type () const
144 return p_ == 0? 0: &this_type::p_;
149 // operator! is a Borland-specific workaround
150 bool operator! () const
155 void swap(intrusive_ptr & rhs)
167 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
169 return a.get() == b.get();
172 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
174 return a.get() != b.get();
177 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, U * b)
182 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, U * b)
187 template<class T, class U> inline bool operator==(T * a, intrusive_ptr<U> const & b)
192 template<class T, class U> inline bool operator!=(T * a, intrusive_ptr<U> const & b)
197 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
199 // Resolve the ambiguity between our op!= and the one in rel_ops
201 template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
203 return a.get() != b.get();
208 template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
210 return std::less<T *>()(a.get(), b.get());
213 template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs)
220 template<class T> T * get_pointer(intrusive_ptr<T> const & p)
225 template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
227 return static_cast<T *>(p.get());
230 template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p)
232 return const_cast<T *>(p.get());
235 template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
237 return dynamic_cast<T *>(p.get());
242 #if defined(__GNUC__) && (__GNUC__ < 3)
244 template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p)
252 // in STLport's no-iostreams mode no iostream symbols can be used
253 #ifndef _STLP_NO_IOSTREAMS
255 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
256 // MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
257 using std::basic_ostream;
258 template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
260 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
267 #endif // _STLP_NO_IOSTREAMS
269 #endif // __GNUC__ < 3
274 # pragma warning(pop)
277 #endif // #ifndef BOOST_INTRUSIVE_PTR_HPP_INCLUDED