]> git.lyx.org Git - features.git/blobdiff - boost/boost/smart_ptr/shared_ptr.hpp
boost: add eol property
[features.git] / boost / boost / smart_ptr / shared_ptr.hpp
index 3a89fc7e4a7223d753173dedeccbfd589fc6e550..1b367f0f4da8da05719b8df75b52cea3f1299db8 100644 (file)
-#ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED\r
-#define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED\r
-\r
-//\r
-//  shared_ptr.hpp\r
-//\r
-//  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.\r
-//  Copyright (c) 2001-2008 Peter Dimov\r
-//\r
-//  Distributed under the Boost Software License, Version 1.0. (See\r
-//  accompanying file LICENSE_1_0.txt or copy at\r
-//  http://www.boost.org/LICENSE_1_0.txt)\r
-//\r
-//  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.\r
-//\r
-\r
-#include <boost/config.hpp>   // for broken compiler workarounds\r
-\r
-#if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)\r
-#include <boost/smart_ptr/detail/shared_ptr_nmt.hpp>\r
-#else\r
-\r
-// In order to avoid circular dependencies with Boost.TR1\r
-// we make sure that our include of <memory> doesn't try to\r
-// pull in the TR1 headers: that's why we use this header \r
-// rather than including <memory> directly:\r
-#include <boost/config/no_tr1/memory.hpp>  // std::auto_ptr\r
-\r
-#include <boost/assert.hpp>\r
-#include <boost/checked_delete.hpp>\r
-#include <boost/throw_exception.hpp>\r
-#include <boost/smart_ptr/detail/shared_count.hpp>\r
-#include <boost/detail/workaround.hpp>\r
-#include <boost/smart_ptr/detail/sp_convertible.hpp>\r
-\r
-#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)\r
-#include <boost/smart_ptr/detail/spinlock_pool.hpp>\r
-#include <boost/memory_order.hpp>\r
-#endif\r
-\r
-#include <algorithm>            // for std::swap\r
-#include <functional>           // for std::less\r
-#include <typeinfo>             // for std::bad_cast\r
-\r
-#if !defined(BOOST_NO_IOSTREAM)\r
-#if !defined(BOOST_NO_IOSFWD)\r
-#include <iosfwd>               // for std::basic_ostream\r
-#else\r
-#include <ostream>\r
-#endif\r
-#endif\r
-\r
-#ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash\r
-# pragma warning(push)\r
-# pragma warning(disable:4284) // odd return type for operator->\r
-#endif\r
-\r
-namespace boost\r
-{\r
-\r
-template<class T> class shared_ptr;\r
-template<class T> class weak_ptr;\r
-template<class T> class enable_shared_from_this;\r
-template<class T> class enable_shared_from_this2;\r
-\r
-namespace detail\r
-{\r
-\r
-struct static_cast_tag {};\r
-struct const_cast_tag {};\r
-struct dynamic_cast_tag {};\r
-struct polymorphic_cast_tag {};\r
-\r
-template<class T> struct shared_ptr_traits\r
-{\r
-    typedef T & reference;\r
-};\r
-\r
-template<> struct shared_ptr_traits<void>\r
-{\r
-    typedef void reference;\r
-};\r
-\r
-#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)\r
-\r
-template<> struct shared_ptr_traits<void const>\r
-{\r
-    typedef void reference;\r
-};\r
-\r
-template<> struct shared_ptr_traits<void volatile>\r
-{\r
-    typedef void reference;\r
-};\r
-\r
-template<> struct shared_ptr_traits<void const volatile>\r
-{\r
-    typedef void reference;\r
-};\r
-\r
-#endif\r
-\r
-// enable_shared_from_this support\r
-\r
-template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )\r
-{\r
-    if( pe != 0 )\r
-    {\r
-        pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );\r
-    }\r
-}\r
-\r
-template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_this2< T > const * pe )\r
-{\r
-    if( pe != 0 )\r
-    {\r
-        pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );\r
-    }\r
-}\r
-\r
-#ifdef _MANAGED\r
-\r
-// Avoid C4793, ... causes native code generation\r
-\r
-struct sp_any_pointer\r
-{\r
-    template<class T> sp_any_pointer( T* ) {}\r
-};\r
-\r
-inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )\r
-{\r
-}\r
-\r
-#else // _MANAGED\r
-\r
-inline void sp_enable_shared_from_this( ... )\r
-{\r
-}\r
-\r
-#endif // _MANAGED\r
-\r
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )\r
-\r
-// rvalue auto_ptr support based on a technique by Dave Abrahams\r
-\r
-template< class T, class R > struct sp_enable_if_auto_ptr\r
-{\r
-};\r
-\r
-template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >\r
-{\r
-    typedef R type;\r
-}; \r
-\r
-#endif\r
-\r
-} // namespace detail\r
-\r
-\r
-//\r
-//  shared_ptr\r
-//\r
-//  An enhanced relative of scoped_ptr with reference counted copy semantics.\r
-//  The object pointed to is deleted when the last shared_ptr pointing to it\r
-//  is destroyed or reset.\r
-//\r
-\r
-template<class T> class shared_ptr\r
-{\r
-private:\r
-\r
-    // Borland 5.5.1 specific workaround\r
-    typedef shared_ptr<T> this_type;\r
-\r
-public:\r
-\r
-    typedef T element_type;\r
-    typedef T value_type;\r
-    typedef T * pointer;\r
-    typedef typename boost::detail::shared_ptr_traits<T>::reference reference;\r
-\r
-    shared_ptr(): px(0), pn() // never throws in 1.30+\r
-    {\r
-    }\r
-\r
-    template<class Y>\r
-    explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete\r
-    {\r
-        boost::detail::sp_enable_shared_from_this( this, p, p );\r
-    }\r
-\r
-    //\r
-    // Requirements: D's copy constructor must not throw\r
-    //\r
-    // shared_ptr will release p by calling d(p)\r
-    //\r
-\r
-    template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)\r
-    {\r
-        boost::detail::sp_enable_shared_from_this( this, p, p );\r
-    }\r
-\r
-    // As above, but with allocator. A's copy constructor shall not throw.\r
-\r
-    template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )\r
-    {\r
-        boost::detail::sp_enable_shared_from_this( this, p, p );\r
-    }\r
-\r
-//  generated copy constructor, destructor are fine\r
-\r
-    template<class Y>\r
-    explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw\r
-    {\r
-        // it is now safe to copy r.px, as pn(r.pn) did not throw\r
-        px = r.px;\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) // never throws\r
-    {\r
-        if( !pn.empty() )\r
-        {\r
-            px = r.px;\r
-        }\r
-    }\r
-\r
-    template<class Y>\r
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )\r
-\r
-    shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )\r
-\r
-#else\r
-\r
-    shared_ptr( shared_ptr<Y> const & r )\r
-\r
-#endif\r
-    : px( r.px ), pn( r.pn ) // never throws\r
-    {\r
-    }\r
-\r
-    // aliasing\r
-    template< class Y >\r
-    shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws\r
-    {\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)\r
-    {\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)\r
-    {\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr(shared_ptr<Y> const & r, boost::detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)\r
-    {\r
-        if(px == 0) // need to allocate new counter -- the cast failed\r
-        {\r
-            pn = boost::detail::shared_count();\r
-        }\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr(shared_ptr<Y> const & r, boost::detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)\r
-    {\r
-        if(px == 0)\r
-        {\r
-            boost::throw_exception(std::bad_cast());\r
-        }\r
-    }\r
-\r
-#ifndef BOOST_NO_AUTO_PTR\r
-\r
-    template<class Y>\r
-    explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()\r
-    {\r
-        Y * tmp = r.get();\r
-        pn = boost::detail::shared_count(r);\r
-        boost::detail::sp_enable_shared_from_this( this, tmp, tmp );\r
-    }\r
-\r
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )\r
-\r
-    template<class Ap>\r
-    explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()\r
-    {\r
-        typename Ap::element_type * tmp = r.get();\r
-        pn = boost::detail::shared_count( r );\r
-        boost::detail::sp_enable_shared_from_this( this, tmp, tmp );\r
-    }\r
-\r
-\r
-#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION\r
-\r
-#endif // BOOST_NO_AUTO_PTR\r
-\r
-    // assignment\r
-\r
-    shared_ptr & operator=( shared_ptr const & r ) // never throws\r
-    {\r
-        this_type(r).swap(*this);\r
-        return *this;\r
-    }\r
-\r
-#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)\r
-\r
-    template<class Y>\r
-    shared_ptr & operator=(shared_ptr<Y> const & r) // never throws\r
-    {\r
-        this_type(r).swap(*this);\r
-        return *this;\r
-    }\r
-\r
-#endif\r
-\r
-#ifndef BOOST_NO_AUTO_PTR\r
-\r
-    template<class Y>\r
-    shared_ptr & operator=( std::auto_ptr<Y> & r )\r
-    {\r
-        this_type(r).swap(*this);\r
-        return *this;\r
-    }\r
-\r
-#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )\r
-\r
-    template<class Ap>\r
-    typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )\r
-    {\r
-        this_type( r ).swap( *this );\r
-        return *this;\r
-    }\r
-\r
-\r
-#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION\r
-\r
-#endif // BOOST_NO_AUTO_PTR\r
-\r
-// Move support\r
-\r
-#if defined( BOOST_HAS_RVALUE_REFS )\r
-\r
-    shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws\r
-    {\r
-        pn.swap( r.pn );\r
-        r.px = 0;\r
-    }\r
-\r
-    template<class Y>\r
-#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )\r
-\r
-    shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )\r
-\r
-#else\r
-\r
-    shared_ptr( shared_ptr<Y> && r )\r
-\r
-#endif\r
-    : px( r.px ), pn() // never throws\r
-    {\r
-        pn.swap( r.pn );\r
-        r.px = 0;\r
-    }\r
-\r
-    shared_ptr & operator=( shared_ptr && r ) // never throws\r
-    {\r
-        this_type( std::move( r ) ).swap( *this );\r
-        return *this;\r
-    }\r
-\r
-    template<class Y>\r
-    shared_ptr & operator=( shared_ptr<Y> && r ) // never throws\r
-    {\r
-        this_type( std::move( r ) ).swap( *this );\r
-        return *this;\r
-    }\r
-\r
-#endif\r
-\r
-    void reset() // never throws in 1.30+\r
-    {\r
-        this_type().swap(*this);\r
-    }\r
-\r
-    template<class Y> void reset(Y * p) // Y must be complete\r
-    {\r
-        BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors\r
-        this_type(p).swap(*this);\r
-    }\r
-\r
-    template<class Y, class D> void reset( Y * p, D d )\r
-    {\r
-        this_type( p, d ).swap( *this );\r
-    }\r
-\r
-    template<class Y, class D, class A> void reset( Y * p, D d, A a )\r
-    {\r
-        this_type( p, d, a ).swap( *this );\r
-    }\r
-\r
-    template<class Y> void reset( shared_ptr<Y> const & r, T * p )\r
-    {\r
-        this_type( r, p ).swap( *this );\r
-    }\r
-\r
-    reference operator* () const // never throws\r
-    {\r
-        BOOST_ASSERT(px != 0);\r
-        return *px;\r
-    }\r
-\r
-    T * operator-> () const // never throws\r
-    {\r
-        BOOST_ASSERT(px != 0);\r
-        return px;\r
-    }\r
-\r
-    T * get() const // never throws\r
-    {\r
-        return px;\r
-    }\r
-\r
-// implicit conversion to "bool"\r
-#include <boost/smart_ptr/detail/operator_bool.hpp>\r
-\r
-    bool unique() const // never throws\r
-    {\r
-        return pn.unique();\r
-    }\r
-\r
-    long use_count() const // never throws\r
-    {\r
-        return pn.use_count();\r
-    }\r
-\r
-    void swap(shared_ptr<T> & other) // never throws\r
-    {\r
-        std::swap(px, other.px);\r
-        pn.swap(other.pn);\r
-    }\r
-\r
-    template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const\r
-    {\r
-        return pn < rhs.pn;\r
-    }\r
-\r
-    void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const\r
-    {\r
-        return pn.get_deleter( ti );\r
-    }\r
-\r
-    bool _internal_equiv( shared_ptr const & r ) const\r
-    {\r
-        return px == r.px && pn == r.pn;\r
-    }\r
-\r
-// Tasteless as this may seem, making all members public allows member templates\r
-// to work in the absence of member template friends. (Matthew Langston)\r
-\r
-#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS\r
-\r
-private:\r
-\r
-    template<class Y> friend class shared_ptr;\r
-    template<class Y> friend class weak_ptr;\r
-\r
-\r
-#endif\r
-\r
-    T * px;                     // contained pointer\r
-    boost::detail::shared_count pn;    // reference counter\r
-\r
-};  // shared_ptr\r
-\r
-template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)\r
-{\r
-    return a.get() == b.get();\r
-}\r
-\r
-template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)\r
-{\r
-    return a.get() != b.get();\r
-}\r
-\r
-#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96\r
-\r
-// Resolve the ambiguity between our op!= and the one in rel_ops\r
-\r
-template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)\r
-{\r
-    return a.get() != b.get();\r
-}\r
-\r
-#endif\r
-\r
-template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)\r
-{\r
-    return a._internal_less(b);\r
-}\r
-\r
-template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)\r
-{\r
-    a.swap(b);\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::static_cast_tag());\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::const_cast_tag());\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());\r
-}\r
-\r
-// shared_*_cast names are deprecated. Use *_pointer_cast instead.\r
-\r
-template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::static_cast_tag());\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)\r
-{\r
-    return shared_ptr<T>(r, boost::detail::polymorphic_cast_tag());\r
-}\r
-\r
-template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)\r
-{\r
-    BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());\r
-    return shared_static_cast<T>(r);\r
-}\r
-\r
-// get_pointer() enables boost::mem_fn to recognize shared_ptr\r
-\r
-template<class T> inline T * get_pointer(shared_ptr<T> const & p)\r
-{\r
-    return p.get();\r
-}\r
-\r
-// operator<<\r
-\r
-#if !defined(BOOST_NO_IOSTREAM)\r
-\r
-#if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) &&  (__GNUC__ < 3) )\r
-\r
-template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)\r
-{\r
-    os << p.get();\r
-    return os;\r
-}\r
-\r
-#else\r
-\r
-// in STLport's no-iostreams mode no iostream symbols can be used\r
-#ifndef _STLP_NO_IOSTREAMS\r
-\r
-# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)\r
-// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL\r
-using std::basic_ostream;\r
-template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)\r
-# else\r
-template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)\r
-# endif\r
-{\r
-    os << p.get();\r
-    return os;\r
-}\r
-\r
-#endif // _STLP_NO_IOSTREAMS\r
-\r
-#endif // __GNUC__ < 3\r
-\r
-#endif // !defined(BOOST_NO_IOSTREAM)\r
-\r
-// get_deleter\r
-\r
-#if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \\r
-    ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \\r
-    ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )\r
-\r
-// g++ 2.9x doesn't allow static_cast<X const *>(void *)\r
-// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it\r
-\r
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)\r
-{\r
-    void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));\r
-    return const_cast<D *>(static_cast<D const *>(q));\r
-}\r
-\r
-#else\r
-\r
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)\r
-{\r
-    return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));\r
-}\r
-\r
-#endif\r
-\r
-// atomic access\r
-\r
-#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)\r
-\r
-template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )\r
-{\r
-    return false;\r
-}\r
-\r
-template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )\r
-{\r
-    boost::detail::spinlock_pool<2>::scoped_lock lock( p );\r
-    return *p;\r
-}\r
-\r
-template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, memory_order /*mo*/ )\r
-{\r
-    return atomic_load( p );\r
-}\r
-\r
-template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )\r
-{\r
-    boost::detail::spinlock_pool<2>::scoped_lock lock( p );\r
-    p->swap( r );\r
-}\r
-\r
-template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )\r
-{\r
-    atomic_store( p, r ); // std::move( r )\r
-}\r
-\r
-template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )\r
-{\r
-    boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );\r
-\r
-    sp.lock();\r
-    p->swap( r );\r
-    sp.unlock();\r
-\r
-    return r; // return std::move( r )\r
-}\r
-\r
-template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )\r
-{\r
-    return atomic_exchange( p, r ); // std::move( r )\r
-}\r
-\r
-template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )\r
-{\r
-    boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );\r
-\r
-    sp.lock();\r
-\r
-    if( p->_internal_equiv( *v ) )\r
-    {\r
-        p->swap( w );\r
-\r
-        sp.unlock();\r
-\r
-        return true;\r
-    }\r
-    else\r
-    {\r
-        shared_ptr<T> tmp( *p );\r
-\r
-        sp.unlock();\r
-\r
-        tmp.swap( *v );\r
-        return false;\r
-    }\r
-}\r
-\r
-template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, memory_order /*success*/, memory_order /*failure*/ )\r
-{\r
-    return atomic_compare_exchange( p, v, w ); // std::move( w )\r
-}\r
-\r
-#endif\r
-\r
-} // namespace boost\r
-\r
-#ifdef BOOST_MSVC\r
-# pragma warning(pop)\r
-#endif\r
-\r
-#endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)\r
-\r
-#endif  // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED\r
+#ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+#define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+
+//
+//  shared_ptr.hpp
+//
+//  (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
+//  Copyright (c) 2001-2008 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)
+//
+//  See http://www.boost.org/libs/smart_ptr/shared_ptr.htm for documentation.
+//
+
+#include <boost/config.hpp>   // for broken compiler workarounds
+
+#if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
+#include <boost/smart_ptr/detail/shared_ptr_nmt.hpp>
+#else
+
+// In order to avoid circular dependencies with Boost.TR1
+// we make sure that our include of <memory> doesn't try to
+// pull in the TR1 headers: that's why we use this header 
+// rather than including <memory> directly:
+#include <boost/config/no_tr1/memory.hpp>  // std::auto_ptr
+
+#include <boost/assert.hpp>
+#include <boost/checked_delete.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/smart_ptr/detail/shared_count.hpp>
+#include <boost/detail/workaround.hpp>
+#include <boost/smart_ptr/detail/sp_convertible.hpp>
+
+#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
+#include <boost/smart_ptr/detail/spinlock_pool.hpp>
+#include <boost/memory_order.hpp>
+#endif
+
+#include <algorithm>            // for std::swap
+#include <functional>           // for std::less
+#include <typeinfo>             // for std::bad_cast
+
+#if !defined(BOOST_NO_IOSTREAM)
+#if !defined(BOOST_NO_IOSFWD)
+#include <iosfwd>               // for std::basic_ostream
+#else
+#include <ostream>
+#endif
+#endif
+
+#ifdef BOOST_MSVC  // moved here to work around VC++ compiler crash
+# pragma warning(push)
+# pragma warning(disable:4284) // odd return type for operator->
+#endif
+
+namespace boost
+{
+
+template<class T> class shared_ptr;
+template<class T> class weak_ptr;
+template<class T> class enable_shared_from_this;
+template<class T> class enable_shared_from_this2;
+
+namespace detail
+{
+
+struct static_cast_tag {};
+struct const_cast_tag {};
+struct dynamic_cast_tag {};
+struct polymorphic_cast_tag {};
+
+template<class T> struct shared_ptr_traits
+{
+    typedef T & reference;
+};
+
+template<> struct shared_ptr_traits<void>
+{
+    typedef void reference;
+};
+
+#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
+
+template<> struct shared_ptr_traits<void const>
+{
+    typedef void reference;
+};
+
+template<> struct shared_ptr_traits<void volatile>
+{
+    typedef void reference;
+};
+
+template<> struct shared_ptr_traits<void const volatile>
+{
+    typedef void reference;
+};
+
+#endif
+
+// enable_shared_from_this support
+
+template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )
+{
+    if( pe != 0 )
+    {
+        pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
+    }
+}
+
+template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_this2< T > const * pe )
+{
+    if( pe != 0 )
+    {
+        pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
+    }
+}
+
+#ifdef _MANAGED
+
+// Avoid C4793, ... causes native code generation
+
+struct sp_any_pointer
+{
+    template<class T> sp_any_pointer( T* ) {}
+};
+
+inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
+{
+}
+
+#else // _MANAGED
+
+inline void sp_enable_shared_from_this( ... )
+{
+}
+
+#endif // _MANAGED
+
+#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
+
+// rvalue auto_ptr support based on a technique by Dave Abrahams
+
+template< class T, class R > struct sp_enable_if_auto_ptr
+{
+};
+
+template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
+{
+    typedef R type;
+}; 
+
+#endif
+
+} // namespace detail
+
+
+//
+//  shared_ptr
+//
+//  An enhanced relative of scoped_ptr with reference counted copy semantics.
+//  The object pointed to is deleted when the last shared_ptr pointing to it
+//  is destroyed or reset.
+//
+
+template<class T> class shared_ptr
+{
+private:
+
+    // Borland 5.5.1 specific workaround
+    typedef shared_ptr<T> this_type;
+
+public:
+
+    typedef T element_type;
+    typedef T value_type;
+    typedef T * pointer;
+    typedef typename boost::detail::shared_ptr_traits<T>::reference reference;
+
+    shared_ptr(): px(0), pn() // never throws in 1.30+
+    {
+    }
+
+    template<class Y>
+    explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
+    {
+        boost::detail::sp_enable_shared_from_this( this, p, p );
+    }
+
+    //
+    // Requirements: D's copy constructor must not throw
+    //
+    // shared_ptr will release p by calling d(p)
+    //
+
+    template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
+    {
+        boost::detail::sp_enable_shared_from_this( this, p, p );
+    }
+
+    // As above, but with allocator. A's copy constructor shall not throw.
+
+    template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
+    {
+        boost::detail::sp_enable_shared_from_this( this, p, p );
+    }
+
+//  generated copy constructor, destructor are fine
+
+    template<class Y>
+    explicit shared_ptr(weak_ptr<Y> const & r): pn(r.pn) // may throw
+    {
+        // it is now safe to copy r.px, as pn(r.pn) did not throw
+        px = r.px;
+    }
+
+    template<class Y>
+    shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag ): px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) // never throws
+    {
+        if( !pn.empty() )
+        {
+            px = r.px;
+        }
+    }
+
+    template<class Y>
+#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+
+    shared_ptr( shared_ptr<Y> const & r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+
+#else
+
+    shared_ptr( shared_ptr<Y> const & r )
+
+#endif
+    : px( r.px ), pn( r.pn ) // never throws
+    {
+    }
+
+    // aliasing
+    template< class Y >
+    shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws
+    {
+    }
+
+    template<class Y>
+    shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
+    {
+    }
+
+    template<class Y>
+    shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
+    {
+    }
+
+    template<class Y>
+    shared_ptr(shared_ptr<Y> const & r, boost::detail::dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
+    {
+        if(px == 0) // need to allocate new counter -- the cast failed
+        {
+            pn = boost::detail::shared_count();
+        }
+    }
+
+    template<class Y>
+    shared_ptr(shared_ptr<Y> const & r, boost::detail::polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
+    {
+        if(px == 0)
+        {
+            boost::throw_exception(std::bad_cast());
+        }
+    }
+
+#ifndef BOOST_NO_AUTO_PTR
+
+    template<class Y>
+    explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
+    {
+        Y * tmp = r.get();
+        pn = boost::detail::shared_count(r);
+        boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
+    }
+
+#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+    template<class Ap>
+    explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
+    {
+        typename Ap::element_type * tmp = r.get();
+        pn = boost::detail::shared_count( r );
+        boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
+    }
+
+
+#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+
+#endif // BOOST_NO_AUTO_PTR
+
+    // assignment
+
+    shared_ptr & operator=( shared_ptr const & r ) // never throws
+    {
+        this_type(r).swap(*this);
+        return *this;
+    }
+
+#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
+
+    template<class Y>
+    shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
+    {
+        this_type(r).swap(*this);
+        return *this;
+    }
+
+#endif
+
+#ifndef BOOST_NO_AUTO_PTR
+
+    template<class Y>
+    shared_ptr & operator=( std::auto_ptr<Y> & r )
+    {
+        this_type(r).swap(*this);
+        return *this;
+    }
+
+#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+
+    template<class Ap>
+    typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
+    {
+        this_type( r ).swap( *this );
+        return *this;
+    }
+
+
+#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+
+#endif // BOOST_NO_AUTO_PTR
+
+// Move support
+
+#if defined( BOOST_HAS_RVALUE_REFS )
+
+    shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws
+    {
+        pn.swap( r.pn );
+        r.px = 0;
+    }
+
+    template<class Y>
+#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+
+    shared_ptr( shared_ptr<Y> && r, typename detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
+
+#else
+
+    shared_ptr( shared_ptr<Y> && r )
+
+#endif
+    : px( r.px ), pn() // never throws
+    {
+        pn.swap( r.pn );
+        r.px = 0;
+    }
+
+    shared_ptr & operator=( shared_ptr && r ) // never throws
+    {
+        this_type( std::move( r ) ).swap( *this );
+        return *this;
+    }
+
+    template<class Y>
+    shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
+    {
+        this_type( std::move( r ) ).swap( *this );
+        return *this;
+    }
+
+#endif
+
+    void reset() // never throws in 1.30+
+    {
+        this_type().swap(*this);
+    }
+
+    template<class Y> void reset(Y * p) // Y must be complete
+    {
+        BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
+        this_type(p).swap(*this);
+    }
+
+    template<class Y, class D> void reset( Y * p, D d )
+    {
+        this_type( p, d ).swap( *this );
+    }
+
+    template<class Y, class D, class A> void reset( Y * p, D d, A a )
+    {
+        this_type( p, d, a ).swap( *this );
+    }
+
+    template<class Y> void reset( shared_ptr<Y> const & r, T * p )
+    {
+        this_type( r, p ).swap( *this );
+    }
+
+    reference operator* () const // never throws
+    {
+        BOOST_ASSERT(px != 0);
+        return *px;
+    }
+
+    T * operator-> () const // never throws
+    {
+        BOOST_ASSERT(px != 0);
+        return px;
+    }
+
+    T * get() const // never throws
+    {
+        return px;
+    }
+
+// implicit conversion to "bool"
+#include <boost/smart_ptr/detail/operator_bool.hpp>
+
+    bool unique() const // never throws
+    {
+        return pn.unique();
+    }
+
+    long use_count() const // never throws
+    {
+        return pn.use_count();
+    }
+
+    void swap(shared_ptr<T> & other) // never throws
+    {
+        std::swap(px, other.px);
+        pn.swap(other.pn);
+    }
+
+    template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
+    {
+        return pn < rhs.pn;
+    }
+
+    void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const
+    {
+        return pn.get_deleter( ti );
+    }
+
+    bool _internal_equiv( shared_ptr const & r ) const
+    {
+        return px == r.px && pn == r.pn;
+    }
+
+// Tasteless as this may seem, making all members public allows member templates
+// to work in the absence of member template friends. (Matthew Langston)
+
+#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
+
+private:
+
+    template<class Y> friend class shared_ptr;
+    template<class Y> friend class weak_ptr;
+
+
+#endif
+
+    T * px;                     // contained pointer
+    boost::detail::shared_count pn;    // reference counter
+
+};  // shared_ptr
+
+template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
+{
+    return a.get() == b.get();
+}
+
+template<class T, class U> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<U> const & b)
+{
+    return a.get() != b.get();
+}
+
+#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
+
+// Resolve the ambiguity between our op!= and the one in rel_ops
+
+template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T> const & b)
+{
+    return a.get() != b.get();
+}
+
+#endif
+
+template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
+{
+    return a._internal_less(b);
+}
+
+template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
+{
+    a.swap(b);
+}
+
+template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::static_cast_tag());
+}
+
+template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::const_cast_tag());
+}
+
+template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
+}
+
+// shared_*_cast names are deprecated. Use *_pointer_cast instead.
+
+template<class T, class U> shared_ptr<T> shared_static_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::static_cast_tag());
+}
+
+template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
+}
+
+template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)
+{
+    return shared_ptr<T>(r, boost::detail::polymorphic_cast_tag());
+}
+
+template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
+{
+    BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
+    return shared_static_cast<T>(r);
+}
+
+// get_pointer() enables boost::mem_fn to recognize shared_ptr
+
+template<class T> inline T * get_pointer(shared_ptr<T> const & p)
+{
+    return p.get();
+}
+
+// operator<<
+
+#if !defined(BOOST_NO_IOSTREAM)
+
+#if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) &&  (__GNUC__ < 3) )
+
+template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
+{
+    os << p.get();
+    return os;
+}
+
+#else
+
+// in STLport's no-iostreams mode no iostream symbols can be used
+#ifndef _STLP_NO_IOSTREAMS
+
+# if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
+// MSVC6 has problems finding std::basic_ostream through the using declaration in namespace _STL
+using std::basic_ostream;
+template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, shared_ptr<Y> const & p)
+# else
+template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, shared_ptr<Y> const & p)
+# endif
+{
+    os << p.get();
+    return os;
+}
+
+#endif // _STLP_NO_IOSTREAMS
+
+#endif // __GNUC__ < 3
+
+#endif // !defined(BOOST_NO_IOSTREAM)
+
+// get_deleter
+
+#if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
+    ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
+    ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
+
+// g++ 2.9x doesn't allow static_cast<X const *>(void *)
+// apparently EDG 2.38 and HP aCC A.03.35 also don't accept it
+
+template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+{
+    void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
+    return const_cast<D *>(static_cast<D const *>(q));
+}
+
+#else
+
+template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+{
+    return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
+}
+
+#endif
+
+// atomic access
+
+#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
+
+template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )
+{
+    return false;
+}
+
+template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
+{
+    boost::detail::spinlock_pool<2>::scoped_lock lock( p );
+    return *p;
+}
+
+template<class T> inline shared_ptr<T> atomic_load_explicit( shared_ptr<T> const * p, memory_order /*mo*/ )
+{
+    return atomic_load( p );
+}
+
+template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
+{
+    boost::detail::spinlock_pool<2>::scoped_lock lock( p );
+    p->swap( r );
+}
+
+template<class T> inline void atomic_store_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
+{
+    atomic_store( p, r ); // std::move( r )
+}
+
+template<class T> shared_ptr<T> atomic_exchange( shared_ptr<T> * p, shared_ptr<T> r )
+{
+    boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
+
+    sp.lock();
+    p->swap( r );
+    sp.unlock();
+
+    return r; // return std::move( r )
+}
+
+template<class T> shared_ptr<T> atomic_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> r, memory_order /*mo*/ )
+{
+    return atomic_exchange( p, r ); // std::move( r )
+}
+
+template<class T> bool atomic_compare_exchange( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w )
+{
+    boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
+
+    sp.lock();
+
+    if( p->_internal_equiv( *v ) )
+    {
+        p->swap( w );
+
+        sp.unlock();
+
+        return true;
+    }
+    else
+    {
+        shared_ptr<T> tmp( *p );
+
+        sp.unlock();
+
+        tmp.swap( *v );
+        return false;
+    }
+}
+
+template<class T> inline bool atomic_compare_exchange_explicit( shared_ptr<T> * p, shared_ptr<T> * v, shared_ptr<T> w, memory_order /*success*/, memory_order /*failure*/ )
+{
+    return atomic_compare_exchange( p, v, w ); // std::move( w )
+}
+
+#endif
+
+} // namespace boost
+
+#ifdef BOOST_MSVC
+# pragma warning(pop)
+#endif
+
+#endif  // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
+
+#endif  // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED