1 #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
2 #define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
34 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
43 #if !defined(BOOST_NO_IOSTREAM)
44 #if !defined(BOOST_NO_IOSFWD)
51 #if defined( BOOST_SP_DISABLE_DEPRECATED )
52 #pragma GCC diagnostic push
53 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
59 template<
class T>
class shared_ptr;
60 template<
class T>
class weak_ptr;
62 class enable_shared_from_raw;
67 template<
class T,
class D >
class unique_ptr;
81 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
88 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
97 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
111 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
128 #endif // !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
130 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
137 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
146 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
155 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
162 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
171 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
180 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
187 #if !defined( __BORLANDC__ ) || !BOOST_WORKAROUND( __BORLANDC__, < 0x600 )
196 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
205 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
212 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
220 pe->_internal_accept_owner( ppx,
const_cast< Y*
>( py ) );
230 struct sp_any_pointer
232 template<
class T> sp_any_pointer(
T* ) {}
247 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
266 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
274 T* p =
static_cast< Y*
>( 0 );
288 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
292 sp_assert_convertible< Y[], T[] >();
298 sp_assert_convertible< Y[N], T[N] >();
302 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
311 #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
315 sp_assert_convertible< Y[], T[] >();
320 sp_assert_convertible< Y[N], T[N] >();
323 #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
336 template<
class T>
class shared_ptr
341 typedef shared_ptr<T> this_type;
351 #if !defined( BOOST_NO_CXX11_NULLPTR )
360 explicit shared_ptr( Y * p ): px( p ), pn()
371 template<
class Y,
class D> shared_ptr( Y * p, D d ): px( p ), pn( p,
d )
376 #if !defined( BOOST_NO_CXX11_NULLPTR )
386 template<
class Y,
class D,
class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p,
d, a )
391 #if !defined( BOOST_NO_CXX11_NULLPTR )
401 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
405 shared_ptr( shared_ptr
const & r )
BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
412 explicit shared_ptr( weak_ptr<Y>
const & r ): pn( r.pn )
414 boost::detail::sp_assert_convertible< Y, T >();
431 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
437 shared_ptr( shared_ptr<Y>
const & r )
442 boost::detail::sp_assert_convertible< Y, T >();
447 shared_ptr( shared_ptr<Y>
const & r, element_type * p )
BOOST_NOEXCEPT : px( p ), pn( r.pn )
451 #ifndef BOOST_NO_AUTO_PTR
454 explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
456 boost::detail::sp_assert_convertible< Y, T >();
464 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
467 shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
469 boost::detail::sp_assert_convertible< Y, T >();
477 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
482 typedef typename Ap::element_type Y;
484 boost::detail::sp_assert_convertible< Y, T >();
492 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
494 #endif // BOOST_NO_AUTO_PTR
496 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
498 template<
class Y,
class D >
499 shared_ptr( std::unique_ptr< Y, D > && r ): px( r.get() ), pn()
501 boost::detail::sp_assert_convertible< Y, T >();
503 typename std::unique_ptr< Y, D >::pointer tmp = r.get();
511 template<
class Y,
class D >
514 boost::detail::sp_assert_convertible< Y, T >();
526 this_type(r).swap(*
this);
530 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
535 this_type(r).swap(*
this);
541 #ifndef BOOST_NO_AUTO_PTR
544 shared_ptr & operator=( std::auto_ptr<Y> & r )
546 this_type( r ).swap( *
this );
550 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
553 shared_ptr & operator=( std::auto_ptr<Y> && r )
555 this_type(
static_cast< std::auto_ptr<Y> &&
>( r ) ).swap( *
this );
559 #elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
564 this_type( r ).swap( *
this );
568 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
570 #endif // BOOST_NO_AUTO_PTR
572 #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
574 template<
class Y,
class D>
575 shared_ptr & operator=( std::unique_ptr<Y, D> && r )
577 this_type(
static_cast< std::unique_ptr<Y, D> &&
>( r ) ).swap(*
this);
583 template<
class Y,
class D>
588 boost::detail::sp_assert_convertible< Y, T >();
606 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
615 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
621 shared_ptr( shared_ptr<Y> && r )
626 boost::detail::sp_assert_convertible< Y, T >();
634 this_type(
static_cast< shared_ptr &&
>( r ) ).swap( *
this );
641 this_type(
static_cast< shared_ptr<Y> &&
>( r ) ).swap( *
this );
647 shared_ptr( shared_ptr<Y> && r, element_type * p )
BOOST_NOEXCEPT : px( p ), pn()
655 #if !defined( BOOST_NO_CXX11_NULLPTR )
659 this_type().swap(*
this);
667 this_type().swap(*
this);
670 template<
class Y>
void reset( Y * p )
673 this_type( p ).swap( *
this );
676 template<
class Y,
class D>
void reset( Y * p, D d )
678 this_type( p, d ).swap( *
this );
681 template<
class Y,
class D,
class A>
void reset( Y * p, D d, A a )
683 this_type( p, d, a ).swap( *
this );
686 template<
class Y>
void reset( shared_ptr<Y>
const & r, element_type * p )
688 this_type( r, p ).swap( *
this );
691 #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
693 template<
class Y>
void reset( shared_ptr<Y> && r, element_type * p )
695 this_type(
static_cast< shared_ptr<Y> &&
>( r ), p ).swap( *
this );
747 template<
class Y>
bool owner_before( shared_ptr<Y>
const & rhs )
const BOOST_NOEXCEPT
752 template<
class Y>
bool owner_before( weak_ptr<Y>
const & rhs )
const BOOST_NOEXCEPT
769 return px == r.px && pn == r.pn;
775 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
779 template<
class Y>
friend class shared_ptr;
780 template<
class Y>
friend class weak_ptr;
792 return a.get() == b.get();
797 return a.get() != b.get();
800 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
806 return a.get() != b.get();
811 #if !defined( BOOST_NO_CXX11_NULLPTR )
837 return a.owner_before( b );
847 (void)
static_cast< T*
>(
static_cast< U*
>( 0 ) );
849 typedef typename shared_ptr<T>::element_type E;
851 E * p =
static_cast< E*
>( r.get() );
857 (void)
const_cast< T*
>(
static_cast< U*
>( 0 ) );
859 typedef typename shared_ptr<T>::element_type E;
861 E * p =
const_cast< E*
>( r.get() );
867 (void)
dynamic_cast< T*
>(
static_cast< U*
>( 0 ) );
869 typedef typename shared_ptr<T>::element_type E;
871 E * p =
dynamic_cast< E*
>( r.get() );
877 (void)
reinterpret_cast< T*
>(
static_cast< U*
>( 0 ) );
879 typedef typename shared_ptr<T>::element_type E;
881 E * p =
reinterpret_cast< E*
>( r.get() );
894 #if !defined(BOOST_NO_IOSTREAM)
896 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
898 template<
class Y> std::ostream &
operator<< (std::ostream & os, shared_ptr<Y>
const & p)
907 #ifndef _STLP_NO_IOSTREAMS
909 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
911 using std::basic_ostream;
912 template<
class E,
class T,
class Y> basic_ostream<E, T> &
operator<< (basic_ostream<E, T> & os, shared_ptr<Y>
const & p)
914 template<
class E,
class T,
class Y> std::basic_ostream<E, T> &
operator<< (std::basic_ostream<E, T> & os,
shared_ptr<Y> const & p)
921 #endif // _STLP_NO_IOSTREAMS
923 #endif // __GNUC__ < 3
925 #endif // !defined(BOOST_NO_IOSTREAM)
932 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
933 ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
934 ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
942 return const_cast<D *
>(
static_cast<D
const *
>(q));
949 return static_cast<D *
>( p._internal_get_deleter(
BOOST_SP_TYPEID(D)) );
973 return boost::detail::basic_get_deleter<D>(
deleter_ );
987 D *
del = boost::detail::basic_get_deleter<D>(p);
994 if(del_wrapper)
del = del_wrapper->::boost::detail::esft2_deleter_wrapper::get_deleter<D>();
1002 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1053 if( p->_internal_equiv( *v ) )
1077 #endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
1090 #if defined( BOOST_SP_DISABLE_DEPRECATED )
1091 #pragma GCC diagnostic pop
1094 #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED