mirror of
https://github.com/boostorg/smart_ptr.git
synced 2026-02-15 13:22:19 +00:00
Add support for shared_ptr<X[N>.
[SVN r81253]
This commit is contained in:
@@ -58,6 +58,11 @@ template< class Y, class T > struct sp_convertible< Y[], T[] >
|
||||
enum _vt { value = sp_convertible< Y[1], T[1] >::value };
|
||||
};
|
||||
|
||||
template< class Y, std::size_t N, class T > struct sp_convertible< Y[N], T[] >
|
||||
{
|
||||
enum _vt { value = sp_convertible< Y[1], T[1] >::value };
|
||||
};
|
||||
|
||||
struct sp_empty
|
||||
{
|
||||
};
|
||||
|
||||
@@ -81,6 +81,11 @@ template< class T > struct sp_element< T[] >
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template< class T, std::size_t N > struct sp_element< T[N] >
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
// sp_dereference, return type of operator*
|
||||
@@ -121,6 +126,11 @@ template< class T > struct sp_dereference< T[] >
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template< class T, std::size_t N > struct sp_dereference< T[N] >
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
// sp_member_access, return type of operator->
|
||||
@@ -137,6 +147,11 @@ template< class T > struct sp_member_access< T[] >
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template< class T, std::size_t N > struct sp_member_access< T[N] >
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
// sp_array_access, return type of operator[]
|
||||
@@ -153,6 +168,27 @@ template< class T > struct sp_array_access< T[] >
|
||||
typedef T & type;
|
||||
};
|
||||
|
||||
template< class T, std::size_t N > struct sp_array_access< T[N] >
|
||||
{
|
||||
typedef T & type;
|
||||
};
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
// sp_extent, for operator[] index check
|
||||
|
||||
template< class T > struct sp_extent
|
||||
{
|
||||
enum _vt { value = 0 };
|
||||
};
|
||||
|
||||
#if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
template< class T, std::size_t N > struct sp_extent< T[N] >
|
||||
{
|
||||
enum _vt { value = N };
|
||||
};
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
// enable_shared_from_this support
|
||||
@@ -207,8 +243,9 @@ template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R
|
||||
|
||||
template< class Y, class T > inline void sp_assert_convertible()
|
||||
{
|
||||
T* p = static_cast< Y* >( 0 );
|
||||
(void)p;
|
||||
// static_assert( sp_convertible< Y, T >::value );
|
||||
typedef char tmp[ sp_convertible< Y, T >::value? 1: -1 ];
|
||||
(void)sizeof( tmp );
|
||||
}
|
||||
|
||||
// pointer constructor helper
|
||||
@@ -224,7 +261,12 @@ template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr
|
||||
template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
|
||||
{
|
||||
sp_assert_convertible< Y[], T[] >();
|
||||
boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
|
||||
}
|
||||
|
||||
template< class T, std::size_t N, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
|
||||
{
|
||||
sp_assert_convertible< Y[N], T[N] >();
|
||||
boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
|
||||
}
|
||||
|
||||
@@ -244,6 +286,11 @@ template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr
|
||||
sp_assert_convertible< Y[], T[] >();
|
||||
}
|
||||
|
||||
template< class T, std::size_t N, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
|
||||
{
|
||||
sp_assert_convertible< Y[N], T[N] >();
|
||||
}
|
||||
|
||||
#endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||
|
||||
} // namespace detail
|
||||
@@ -547,7 +594,7 @@ public:
|
||||
typename boost::detail::sp_array_access< T >::type operator[] ( std::ptrdiff_t i ) const // never throws
|
||||
{
|
||||
BOOST_ASSERT( px != 0 );
|
||||
BOOST_ASSERT( i >= 0 );
|
||||
BOOST_ASSERT( i >= 0 && ( i < boost::detail::sp_extent< T >::value || boost::detail::sp_extent< T >::value == 0 ) );
|
||||
|
||||
return px[ i ];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user