1 #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
2 #define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
17 #include <boost/config.hpp>
19 #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
20 #include <boost/smart_ptr/detail/shared_ptr_nmt.hpp>
27 #include <boost/config/no_tr1/memory.hpp>
29 #include <boost/assert.hpp>
30 #include <boost/checked_delete.hpp>
31 #include <boost/throw_exception.hpp>
32 #include <boost/smart_ptr/detail/shared_count.hpp>
33 #include <boost/detail/workaround.hpp>
34 #include <boost/smart_ptr/detail/sp_convertible.hpp>
36 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
37 #include <boost/smart_ptr/detail/spinlock_pool.hpp>
38 #include <boost/memory_order.hpp>
46 #if !defined(BOOST_NO_IOSTREAM)
47 #if !defined(BOOST_NO_IOSFWD)
80 #if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
105 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
113 pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
121 struct sp_any_pointer
123 template<
class T> sp_any_pointer(
T* ) {}
138 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR )
225 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
259 pn = boost::detail::shared_count();
268 boost::throw_exception(std::bad_cast());
272 #ifndef BOOST_NO_AUTO_PTR
278 pn = boost::detail::shared_count(r);
282 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
287 typename Ap::element_type *
tmp = r.get();
288 pn = boost::detail::shared_count( r );
293 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
295 #endif // BOOST_NO_AUTO_PTR
305 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
316 #ifndef BOOST_NO_AUTO_PTR
325 #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
335 #endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
337 #endif // BOOST_NO_AUTO_PTR
341 #if defined( BOOST_HAS_RVALUE_REFS )
350 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
352 shared_ptr(
shared_ptr<Y> && r,
typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() )
367 this_type( static_cast< shared_ptr && >( r ) ).swap( *
this );
387 BOOST_ASSERT(p == 0 || p !=
px);
408 BOOST_ASSERT(
px != 0);
414 BOOST_ASSERT(
px != 0);
424 #include <boost/smart_ptr/detail/operator_bool.hpp>
433 return pn.use_count();
449 return pn.get_deleter( ti );
460 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
471 boost::detail::shared_count
pn;
477 return a.
get() == b.
get();
482 return a.
get() != b.
get();
485 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
491 return a.get() != b.get();
496 template<
class T,
class U>
inline bool operator<(shared_ptr<T>
const &
a,
shared_ptr<U> const &
b)
498 return a._internal_less(b);
540 BOOST_ASSERT(dynamic_cast<T *>(r.
get()) == r.
get());
553 #if !defined(BOOST_NO_IOSTREAM)
555 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
557 template<
class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y>
const &
p)
566 #ifndef _STLP_NO_IOSTREAMS
568 # if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300 && __SGI_STL_PORT)
570 using std::basic_ostream;
571 template<
class E,
class T,
class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os,
shared_ptr<Y> const &
p)
573 template<class E, class T, class Y> std::basic_ostream<E, T> &
operator<< (std::basic_ostream<E, T> & os,
shared_ptr<Y> const &
p)
580 #endif // _STLP_NO_IOSTREAMS
582 #endif // __GNUC__ < 3
584 #endif // !defined(BOOST_NO_IOSTREAM)
588 #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \
589 ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \
590 ( defined(__HP_aCC) && BOOST_WORKAROUND(__HP_aCC, <= 33500) )
597 void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(
D));
598 return const_cast<D *
>(
static_cast<D const *
>(q));
612 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
621 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
632 boost::detail::spinlock_pool<2>::scoped_lock lock( p );
643 boost::detail::spinlock &
sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
659 boost::detail::spinlock &
sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
687 #endif // !defined(BOOST_SP_NO_ATOMIC_ACCESS)
691 template<
class T >
struct hash;
695 return boost::hash< T* >()( p.
get() );
700 #endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
702 #endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED