Refs #2814 (fixed in trunk.)

[SVN r51518]
This commit is contained in:
Peter Dimov
2009-03-01 18:42:44 +00:00
parent 905a3711db
commit a378c8c278
6 changed files with 112 additions and 240 deletions

View File

@ -0,0 +1,56 @@
// This header intentionally has no include guards.
//
// Copyright (c) 2001-2009 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
operator bool () const
{
return px != 0;
}
#elif defined( _MANAGED )
static void unspecified_bool( this_type*** )
{
}
typedef void (*unspecified_bool_type)( this_type*** );
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: unspecified_bool;
}
#elif \
( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}
#endif
// operator! is redundant, but some compilers need it
bool operator! () const // never throws
{
return px == 0;
}

View File

@ -63,13 +63,13 @@ public:
typedef T element_type; typedef T element_type;
intrusive_ptr(): p_(0) intrusive_ptr(): px( 0 )
{ {
} }
intrusive_ptr(T * p, bool add_ref = true): p_(p) intrusive_ptr( T * p, bool add_ref = true ): px( p )
{ {
if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_); if( px != 0 && add_ref ) intrusive_ptr_add_ref( px );
} }
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
@ -84,21 +84,21 @@ public:
intrusive_ptr( intrusive_ptr<U> const & rhs ) intrusive_ptr( intrusive_ptr<U> const & rhs )
#endif #endif
: p_( rhs.get() ) : px( rhs.get() )
{ {
if( p_ != 0 ) intrusive_ptr_add_ref( p_ ); if( px != 0 ) intrusive_ptr_add_ref( px );
} }
#endif #endif
intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_) intrusive_ptr(intrusive_ptr const & rhs): px( rhs.px )
{ {
if(p_ != 0) intrusive_ptr_add_ref(p_); if( px != 0 ) intrusive_ptr_add_ref( px );
} }
~intrusive_ptr() ~intrusive_ptr()
{ {
if(p_ != 0) intrusive_ptr_release(p_); if( px != 0 ) intrusive_ptr_release( px );
} }
#if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES) #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
@ -135,63 +135,34 @@ public:
T * get() const T * get() const
{ {
return p_; return px;
} }
T & operator*() const T & operator*() const
{ {
BOOST_ASSERT( p_ != 0 ); BOOST_ASSERT( px != 0 );
return *p_; return *px;
} }
T * operator->() const T * operator->() const
{ {
BOOST_ASSERT( p_ != 0 ); BOOST_ASSERT( px != 0 );
return p_; return px;
} }
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530) // implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
operator bool () const
{
return p_ != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return p_ == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type () const
{
return p_ == 0? 0: &this_type::p_;
}
#endif
// operator! is a Borland-specific workaround
bool operator! () const
{
return p_ == 0;
}
void swap(intrusive_ptr & rhs) void swap(intrusive_ptr & rhs)
{ {
T * tmp = p_; T * tmp = px;
p_ = rhs.p_; px = rhs.px;
rhs.p_ = tmp; rhs.px = tmp;
} }
private: private:
T * p_; T * px;
}; };
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)

View File

@ -39,7 +39,7 @@ template<class T> class scoped_array // noncopyable
{ {
private: private:
T * ptr; T * px;
scoped_array(scoped_array const &); scoped_array(scoped_array const &);
scoped_array & operator=(scoped_array const &); scoped_array & operator=(scoped_array const &);
@ -53,79 +53,48 @@ public:
typedef T element_type; typedef T element_type;
explicit scoped_array(T * p = 0) : ptr(p) // never throws explicit scoped_array( T * p = 0 ) : px( p ) // never throws
{ {
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_array_constructor_hook(ptr); boost::sp_array_constructor_hook( px );
#endif #endif
} }
~scoped_array() // never throws ~scoped_array() // never throws
{ {
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_array_destructor_hook(ptr); boost::sp_array_destructor_hook( px );
#endif #endif
boost::checked_array_delete(ptr); boost::checked_array_delete( px );
} }
void reset(T * p = 0) // never throws void reset(T * p = 0) // never throws
{ {
BOOST_ASSERT(p == 0 || p != ptr); // catch self-reset errors BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
this_type(p).swap(*this); this_type(p).swap(*this);
} }
T & operator[](std::ptrdiff_t i) const // never throws T & operator[](std::ptrdiff_t i) const // never throws
{ {
BOOST_ASSERT(ptr != 0); BOOST_ASSERT( px != 0 );
BOOST_ASSERT(i >= 0); BOOST_ASSERT( i >= 0 );
return ptr[i]; return px[i];
} }
T * get() const // never throws T * get() const // never throws
{ {
return ptr; return px;
} }
// implicit conversion to "bool" // implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return ptr != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::ptr;
}
#endif
bool operator! () const // never throws
{
return ptr == 0;
}
void swap(scoped_array & b) // never throws void swap(scoped_array & b) // never throws
{ {
T * tmp = b.ptr; T * tmp = b.px;
b.ptr = ptr; b.px = px;
ptr = tmp; px = tmp;
} }
}; };
template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws template<class T> inline void swap(scoped_array<T> & a, scoped_array<T> & b) // never throws

View File

@ -40,7 +40,7 @@ template<class T> class scoped_ptr // noncopyable
{ {
private: private:
T * ptr; T * px;
scoped_ptr(scoped_ptr const &); scoped_ptr(scoped_ptr const &);
scoped_ptr & operator=(scoped_ptr const &); scoped_ptr & operator=(scoped_ptr const &);
@ -54,19 +54,19 @@ public:
typedef T element_type; typedef T element_type;
explicit scoped_ptr(T * p = 0): ptr(p) // never throws explicit scoped_ptr( T * p = 0 ): px( p ) // never throws
{ {
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_scalar_constructor_hook(ptr); boost::sp_scalar_constructor_hook( px );
#endif #endif
} }
#ifndef BOOST_NO_AUTO_PTR #ifndef BOOST_NO_AUTO_PTR
explicit scoped_ptr(std::auto_ptr<T> p): ptr(p.release()) // never throws explicit scoped_ptr( std::auto_ptr<T> p ): px( p.release() ) // never throws
{ {
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_scalar_constructor_hook(ptr); boost::sp_scalar_constructor_hook( px );
#endif #endif
} }
@ -75,71 +75,42 @@ public:
~scoped_ptr() // never throws ~scoped_ptr() // never throws
{ {
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_scalar_destructor_hook(ptr); boost::sp_scalar_destructor_hook( px );
#endif #endif
boost::checked_delete(ptr); boost::checked_delete( px );
} }
void reset(T * p = 0) // never throws void reset(T * p = 0) // never throws
{ {
BOOST_ASSERT(p == 0 || p != ptr); // catch self-reset errors BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
this_type(p).swap(*this); this_type(p).swap(*this);
} }
T & operator*() const // never throws T & operator*() const // never throws
{ {
BOOST_ASSERT(ptr != 0); BOOST_ASSERT( px != 0 );
return *ptr; return *px;
} }
T * operator->() const // never throws T * operator->() const // never throws
{ {
BOOST_ASSERT(ptr != 0); BOOST_ASSERT( px != 0 );
return ptr; return px;
} }
T * get() const // never throws T * get() const // never throws
{ {
return ptr; return px;
} }
// implicit conversion to "bool" // implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return ptr != 0;
}
#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return ptr == 0? 0: &this_type::ptr;
}
#endif
bool operator! () const // never throws
{
return ptr == 0;
}
void swap(scoped_ptr & b) // never throws void swap(scoped_ptr & b) // never throws
{ {
T * tmp = b.ptr; T * tmp = b.px;
b.ptr = ptr; b.px = px;
ptr = tmp; px = tmp;
} }
}; };

View File

@ -94,54 +94,8 @@ public:
return px; return px;
} }
// implicit conversion to "bool" // implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
operator bool () const
{
return px != 0;
}
#elif defined( _MANAGED )
static void unspecified_bool( this_type*** )
{
}
typedef void (*unspecified_bool_type)( this_type*** );
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: unspecified_bool;
}
#elif \
( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) )
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}
#endif
bool operator! () const // never throws
{
return px == 0;
}
bool unique() const // never throws bool unique() const // never throws
{ {

View File

@ -425,57 +425,8 @@ public:
return px; return px;
} }
// implicit conversion to "bool" // implicit conversion to "bool"
#include <boost/smart_ptr/detail/operator_bool.hpp>
#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
operator bool () const
{
return px != 0;
}
#elif defined( _MANAGED )
static void unspecified_bool( this_type*** )
{
}
typedef void (*unspecified_bool_type)( this_type*** );
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: unspecified_bool;
}
#elif \
( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
typedef T * (this_type::*unspecified_bool_type)() const;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::get;
}
#else
typedef T * this_type::*unspecified_bool_type;
operator unspecified_bool_type() const // never throws
{
return px == 0? 0: &this_type::px;
}
#endif
// operator! is redundant, but some compilers need it
bool operator! () const // never throws
{
return px == 0;
}
bool unique() const // never throws bool unique() const // never throws
{ {