mirror of git://gcc.gnu.org/git/gcc.git
boost_shared_ptr.h: Trivial formatting fixes.
2006-09-22 Paolo Carlini <pcarlini@suse.de> * include/tr1/boost_shared_ptr.h: Trivial formatting fixes. From-SVN: r117145
This commit is contained in:
parent
53e3e587a9
commit
459f9f82ec
|
|
@ -1,3 +1,7 @@
|
|||
2006-09-22 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/tr1/boost_shared_ptr.h: Trivial formatting fixes.
|
||||
|
||||
2006-09-21 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* include/ext/type_traits.h (__numeric_traits_integer): New.
|
||||
|
|
|
|||
|
|
@ -58,31 +58,32 @@ namespace std
|
|||
{
|
||||
_GLIBCXX_BEGIN_NAMESPACE(tr1)
|
||||
|
||||
class bad_weak_ptr : public std::exception
|
||||
{
|
||||
public:
|
||||
class bad_weak_ptr : public std::exception
|
||||
{
|
||||
public:
|
||||
virtual char const*
|
||||
what() const throw() { return "tr1::bad_weak_ptr"; }
|
||||
};
|
||||
what() const throw()
|
||||
{ return "tr1::bad_weak_ptr"; }
|
||||
};
|
||||
|
||||
// Substitute for bad_weak_ptr object in the case of -fno-exceptions.
|
||||
inline void
|
||||
__throw_bad_weak_ptr()
|
||||
{
|
||||
inline void
|
||||
__throw_bad_weak_ptr()
|
||||
{
|
||||
#if __EXCEPTIONS
|
||||
throw bad_weak_ptr();
|
||||
#else
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
using __gnu_cxx::_Lock_policy;
|
||||
using __gnu_cxx::__default_lock_policy;
|
||||
using __gnu_cxx::_S_single;
|
||||
using __gnu_cxx::_S_mutex;
|
||||
using __gnu_cxx::_S_atomic;
|
||||
using __gnu_cxx::_Lock_policy;
|
||||
using __gnu_cxx::__default_lock_policy;
|
||||
using __gnu_cxx::_S_single;
|
||||
using __gnu_cxx::_S_mutex;
|
||||
using __gnu_cxx::_S_atomic;
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp>
|
||||
struct _Sp_deleter
|
||||
{
|
||||
typedef void result_type;
|
||||
|
|
@ -93,17 +94,16 @@ template<typename _Tp>
|
|||
{ delete p; }
|
||||
};
|
||||
|
||||
// Empty helper class except when the template argument is _S_mutex.
|
||||
template<_Lock_policy _Lp>
|
||||
// Empty helper class except when the template argument is _S_mutex.
|
||||
template<_Lock_policy _Lp>
|
||||
class _Mutex_base
|
||||
{ };
|
||||
|
||||
template<>
|
||||
template<>
|
||||
class _Mutex_base<_S_mutex> : public __gnu_cxx::__mutex
|
||||
{ };
|
||||
|
||||
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
class _Sp_counted_base : public _Mutex_base<_Lp>
|
||||
{
|
||||
public:
|
||||
|
|
@ -139,10 +139,10 @@ template<_Lock_policy _Lp = __default_lock_policy>
|
|||
if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1)
|
||||
{
|
||||
dispose();
|
||||
#ifdef __GTHREADS
|
||||
#ifdef __GTHREADS
|
||||
_GLIBCXX_READ_MEM_BARRIER;
|
||||
_GLIBCXX_WRITE_MEM_BARRIER;
|
||||
#endif
|
||||
#endif
|
||||
if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
|
||||
destroy();
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ template<_Lock_policy _Lp = __default_lock_policy>
|
|||
_Atomic_word _M_weak_count; // #weak + (#shared != 0)
|
||||
};
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void
|
||||
_Sp_counted_base<_S_single>::add_ref_lock()
|
||||
{
|
||||
|
|
@ -189,7 +189,7 @@ template<>
|
|||
}
|
||||
|
||||
#ifdef __GTHREADS
|
||||
template<>
|
||||
template<>
|
||||
inline void
|
||||
_Sp_counted_base<_S_mutex>::add_ref_lock()
|
||||
{
|
||||
|
|
@ -202,7 +202,7 @@ template<>
|
|||
}
|
||||
#endif
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void
|
||||
_Sp_counted_base<_S_atomic>::add_ref_lock()
|
||||
{
|
||||
|
|
@ -217,10 +217,11 @@ template<>
|
|||
// Replace the current counter value with the old value + 1, as
|
||||
// long as it's not changed meanwhile.
|
||||
}
|
||||
while (!__sync_bool_compare_and_swap(&_M_use_count, __count, __count + 1));
|
||||
while (!__sync_bool_compare_and_swap(&_M_use_count, __count,
|
||||
__count + 1));
|
||||
}
|
||||
|
||||
template<typename _Ptr, typename _Deleter, _Lock_policy _Lp>
|
||||
template<typename _Ptr, typename _Deleter, _Lock_policy _Lp>
|
||||
class _Sp_counted_base_impl : public _Sp_counted_base<_Lp>
|
||||
{
|
||||
public:
|
||||
|
|
@ -247,10 +248,10 @@ template<typename _Ptr, typename _Deleter, _Lock_policy _Lp>
|
|||
_Deleter _M_del; // copy constructor must not throw
|
||||
};
|
||||
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
class weak_count;
|
||||
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
template<_Lock_policy _Lp = __default_lock_policy>
|
||||
class shared_count
|
||||
{
|
||||
private:
|
||||
|
|
@ -278,7 +279,8 @@ template<_Lock_policy _Lp = __default_lock_policy>
|
|||
|
||||
// Special case for auto_ptr<_Tp> to provide the strong guarantee.
|
||||
template<typename _Tp>
|
||||
explicit shared_count(std::auto_ptr<_Tp>& __r)
|
||||
explicit
|
||||
shared_count(std::auto_ptr<_Tp>& __r)
|
||||
: _M_pi(new _Sp_counted_base_impl<_Tp*,
|
||||
_Sp_deleter<_Tp>, _Lp >(__r.get(), _Sp_deleter<_Tp>()))
|
||||
{ __r.release(); }
|
||||
|
|
@ -314,7 +316,8 @@ template<_Lock_policy _Lp = __default_lock_policy>
|
|||
return *this;
|
||||
}
|
||||
|
||||
void swap(shared_count& __r) // nothrow
|
||||
void
|
||||
swap(shared_count& __r) // nothrow
|
||||
{
|
||||
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
|
||||
__r._M_pi = _M_pi;
|
||||
|
|
@ -342,7 +345,7 @@ template<_Lock_policy _Lp = __default_lock_policy>
|
|||
{ return _M_pi ? _M_pi->get_deleter(__ti) : 0; }
|
||||
};
|
||||
|
||||
template<_Lock_policy _Lp>
|
||||
template<_Lock_policy _Lp>
|
||||
class weak_count
|
||||
{
|
||||
private:
|
||||
|
|
@ -420,9 +423,10 @@ template<_Lock_policy _Lp>
|
|||
{ return std::less<_Sp_counted_base<_Lp>*>()(__a._M_pi, __b._M_pi); }
|
||||
};
|
||||
|
||||
template<_Lock_policy _Lp>
|
||||
template<_Lock_policy _Lp>
|
||||
inline
|
||||
shared_count<_Lp>::shared_count(const weak_count<_Lp>& __r)
|
||||
shared_count<_Lp>::
|
||||
shared_count(const weak_count<_Lp>& __r)
|
||||
: _M_pi(__r._M_pi)
|
||||
{
|
||||
if (_M_pi != 0)
|
||||
|
|
@ -432,68 +436,68 @@ template<_Lock_policy _Lp>
|
|||
}
|
||||
|
||||
|
||||
// Forward decls.
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
// Forward decls.
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
class __shared_ptr;
|
||||
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
class __weak_ptr;
|
||||
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
class __enable_shared_from_this;
|
||||
|
||||
struct __static_cast_tag { };
|
||||
struct __const_cast_tag { };
|
||||
struct __dynamic_cast_tag { };
|
||||
struct __polymorphic_cast_tag { };
|
||||
struct __static_cast_tag { };
|
||||
struct __const_cast_tag { };
|
||||
struct __dynamic_cast_tag { };
|
||||
struct __polymorphic_cast_tag { };
|
||||
|
||||
template<class _Tp>
|
||||
struct shared_ptr_traits
|
||||
{ typedef _Tp& reference; };
|
||||
template<class _Tp>
|
||||
struct __shared_ptr_reference
|
||||
{ typedef _Tp& __type; };
|
||||
|
||||
template<>
|
||||
struct shared_ptr_traits<void>
|
||||
{ typedef void reference; };
|
||||
template<>
|
||||
struct __shared_ptr_reference<void>
|
||||
{ typedef void __type; };
|
||||
|
||||
template<>
|
||||
struct shared_ptr_traits<void const>
|
||||
{ typedef void reference; };
|
||||
template<>
|
||||
struct __shared_ptr_reference<void const>
|
||||
{ typedef void __type; };
|
||||
|
||||
template<>
|
||||
struct shared_ptr_traits<void volatile>
|
||||
{ typedef void reference; };
|
||||
template<>
|
||||
struct __shared_ptr_reference<void volatile>
|
||||
{ typedef void __type; };
|
||||
|
||||
template<>
|
||||
struct shared_ptr_traits<void const volatile>
|
||||
{ typedef void reference; };
|
||||
template<>
|
||||
struct __shared_ptr_reference<void const volatile>
|
||||
{ typedef void __type; };
|
||||
|
||||
|
||||
// Support for enable_shared_from_this.
|
||||
// Support for enable_shared_from_this.
|
||||
|
||||
// Friend of __enable_shared_from_this.
|
||||
template<_Lock_policy _Lp, typename _Tp1, typename _Tp2>
|
||||
// Friend of __enable_shared_from_this.
|
||||
template<_Lock_policy _Lp, typename _Tp1, typename _Tp2>
|
||||
void
|
||||
__enable_shared_from_this_helper(const shared_count<_Lp>&,
|
||||
const __enable_shared_from_this<_Tp1, _Lp>*,
|
||||
const _Tp2*);
|
||||
const __enable_shared_from_this<_Tp1,
|
||||
_Lp>*, const _Tp2*);
|
||||
|
||||
template<_Lock_policy _Lp>
|
||||
template<_Lock_policy _Lp>
|
||||
inline void
|
||||
__enable_shared_from_this_helper(const shared_count<_Lp>&, ...)
|
||||
{ }
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @class shared_ptr <tr1/memory>
|
||||
*
|
||||
* A smart pointer with reference-counted copy semantics.
|
||||
* The object pointed to is deleted when the last shared_ptr pointing to it
|
||||
* is destroyed or reset.
|
||||
* The object pointed to is deleted when the last shared_ptr pointing to
|
||||
* it is destroyed or reset.
|
||||
*/
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
class __shared_ptr
|
||||
{
|
||||
typedef typename shared_ptr_traits<_Tp>::reference _Reference;
|
||||
typedef typename __shared_ptr_reference<_Tp>::__type _Reference;
|
||||
|
||||
public:
|
||||
typedef _Tp element_type;
|
||||
|
|
@ -511,7 +515,8 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
* @throw std::bad_alloc, in which case @c delete @a p is called.
|
||||
*/
|
||||
template<typename _Tp1>
|
||||
explicit __shared_ptr(_Tp1* __p)
|
||||
explicit
|
||||
__shared_ptr(_Tp1* __p)
|
||||
: _M_ptr(__p), _M_refcount(__p, _Sp_deleter<_Tp1>())
|
||||
{
|
||||
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
|
||||
|
|
@ -542,8 +547,9 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
|
||||
// generated copy constructor, assignment, destructor are fine.
|
||||
|
||||
/** @brief If @a r is empty, constructs an empty %__shared_ptr; otherwise
|
||||
* construct a %__shared_ptr that shares ownership with @a r.
|
||||
/** @brief If @a r is empty, constructs an empty %__shared_ptr;
|
||||
* otherwise construct a %__shared_ptr that shares ownership
|
||||
* with @a r.
|
||||
* @param r A %__shared_ptr.
|
||||
* @post get() == r.get() && use_count() == r.use_count()
|
||||
* @throw std::bad_alloc, in which case
|
||||
|
|
@ -561,7 +567,8 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
* in which case the constructor has no effect.
|
||||
*/
|
||||
template<typename _Tp1>
|
||||
explicit __shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
|
||||
explicit
|
||||
__shared_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
|
||||
: _M_refcount(__r._M_refcount) // may throw
|
||||
{
|
||||
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
|
||||
|
|
@ -574,7 +581,8 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
* @post use_count() == 1 and r.get() == 0
|
||||
*/
|
||||
template<typename _Tp1>
|
||||
explicit __shared_ptr(std::auto_ptr<_Tp1>& __r)
|
||||
explicit
|
||||
__shared_ptr(std::auto_ptr<_Tp1>& __r)
|
||||
: _M_ptr(__r.get()), _M_refcount()
|
||||
{
|
||||
// TODO requires r.release() convertible to _Tp*, Tp1 is complete,
|
||||
|
|
@ -718,45 +726,45 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
shared_count<_Lp> _M_refcount; // Reference counter.
|
||||
};
|
||||
|
||||
// 2.2.3.8 shared_ptr specialized algorithms.
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
// 2.2.3.8 shared_ptr specialized algorithms.
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
inline void
|
||||
swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b)
|
||||
{ __a.swap(__b); }
|
||||
|
||||
// 2.2.3.9 shared_ptr casts
|
||||
/** @warning The seemingly equivalent
|
||||
// 2.2.3.9 shared_ptr casts
|
||||
/** @warning The seemingly equivalent
|
||||
* <code>shared_ptr<T>(static_cast<T*>(r.get()))</code>
|
||||
* will eventually result in undefined behaviour,
|
||||
* attempting to delete the same object twice.
|
||||
*/
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
__shared_ptr<_Tp, _Lp>
|
||||
static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
|
||||
{ return __shared_ptr<_Tp, _Lp>(__r, __static_cast_tag()); }
|
||||
|
||||
/** @warning The seemingly equivalent
|
||||
/** @warning The seemingly equivalent
|
||||
* <code>shared_ptr<T>(const_cast<T*>(r.get()))</code>
|
||||
* will eventually result in undefined behaviour,
|
||||
* attempting to delete the same object twice.
|
||||
*/
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
__shared_ptr<_Tp, _Lp>
|
||||
const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
|
||||
{ return __shared_ptr<_Tp, _Lp>(__r, __const_cast_tag()); }
|
||||
|
||||
/** @warning The seemingly equivalent
|
||||
/** @warning The seemingly equivalent
|
||||
* <code>shared_ptr<T>(dynamic_cast<T*>(r.get()))</code>
|
||||
* will eventually result in undefined behaviour,
|
||||
* attempting to delete the same object twice.
|
||||
*/
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
|
||||
__shared_ptr<_Tp, _Lp>
|
||||
dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
|
||||
{ return __shared_ptr<_Tp, _Lp>(__r, __dynamic_cast_tag()); }
|
||||
|
||||
// 2.2.3.7 shared_ptr I/O
|
||||
template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
|
||||
// 2.2.3.7 shared_ptr I/O
|
||||
template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
|
||||
std::basic_ostream<_Ch, _Tr>&
|
||||
operator<<(std::basic_ostream<_Ch, _Tr>& __os,
|
||||
const __shared_ptr<_Tp, _Lp>& __p)
|
||||
|
|
@ -765,14 +773,14 @@ template<typename _Ch, typename _Tr, typename _Tp, _Lock_policy _Lp>
|
|||
return __os;
|
||||
}
|
||||
|
||||
// 2.2.3.10 shared_ptr get_deleter (experimental)
|
||||
template<typename _Del, typename _Tp, _Lock_policy _Lp>
|
||||
// 2.2.3.10 shared_ptr get_deleter (experimental)
|
||||
template<typename _Del, typename _Tp, _Lock_policy _Lp>
|
||||
inline _Del*
|
||||
get_deleter(const __shared_ptr<_Tp, _Lp>& __p)
|
||||
{ return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del))); }
|
||||
|
||||
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
class __weak_ptr
|
||||
{
|
||||
public:
|
||||
|
|
@ -903,14 +911,14 @@ template<typename _Tp, _Lock_policy _Lp>
|
|||
weak_count<_Lp> _M_refcount; // Reference counter.
|
||||
};
|
||||
|
||||
// 2.2.4.7 weak_ptr specialized algorithms.
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
// 2.2.4.7 weak_ptr specialized algorithms.
|
||||
template<typename _Tp, _Lock_policy _Lp>
|
||||
void
|
||||
swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b)
|
||||
{ __a.swap(__b); }
|
||||
|
||||
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
||||
class __enable_shared_from_this
|
||||
{
|
||||
protected:
|
||||
|
|
@ -958,12 +966,12 @@ template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
|
|||
mutable __weak_ptr<_Tp, _Lp> _M_weak_this;
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp>
|
||||
class shared_ptr;
|
||||
|
||||
// The actual TR1 weak_ptr, with forwarding constructors and
|
||||
// assignment operators.
|
||||
template<typename _Tp>
|
||||
// The actual TR1 weak_ptr, with forwarding constructors and
|
||||
// assignment operators.
|
||||
template<typename _Tp>
|
||||
class weak_ptr : public __weak_ptr<_Tp>
|
||||
{
|
||||
public:
|
||||
|
|
@ -992,16 +1000,17 @@ template<typename _Tp>
|
|||
}
|
||||
};
|
||||
|
||||
// The actual TR1 shared_ptr, with forwarding constructors and
|
||||
// assignment operators.
|
||||
template<typename _Tp>
|
||||
// The actual TR1 shared_ptr, with forwarding constructors and
|
||||
// assignment operators.
|
||||
template<typename _Tp>
|
||||
class shared_ptr : public __shared_ptr<_Tp>
|
||||
{
|
||||
public:
|
||||
shared_ptr() : __shared_ptr<_Tp>() { }
|
||||
|
||||
template<typename _Tp1>
|
||||
explicit shared_ptr(_Tp1* __p)
|
||||
explicit
|
||||
shared_ptr(_Tp1* __p)
|
||||
: __shared_ptr<_Tp>(__p) { }
|
||||
|
||||
template<typename _Tp1, typename _Deleter>
|
||||
|
|
@ -1013,11 +1022,13 @@ template<typename _Tp>
|
|||
: __shared_ptr<_Tp>(__r) { }
|
||||
|
||||
template<typename _Tp1>
|
||||
explicit shared_ptr(const __weak_ptr<_Tp1>& __r)
|
||||
explicit
|
||||
shared_ptr(const __weak_ptr<_Tp1>& __r)
|
||||
: __shared_ptr<_Tp>(__r) { }
|
||||
|
||||
template<typename _Tp1>
|
||||
explicit shared_ptr(std::auto_ptr<_Tp1>& __r)
|
||||
explicit
|
||||
shared_ptr(std::auto_ptr<_Tp1>& __r)
|
||||
: __shared_ptr<_Tp>(__r) { }
|
||||
|
||||
template<typename _Tp1>
|
||||
|
|
@ -1050,7 +1061,7 @@ template<typename _Tp>
|
|||
}
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp>
|
||||
class enable_shared_from_this : public __enable_shared_from_this<_Tp>
|
||||
{
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue