Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81715 - in branches/release: . boost boost/smart_ptr libs libs/smart_ptr libs/smart_ptr/test
From: glenfe_at_[hidden]
Date: 2012-12-04 23:13:52


Author: glenfe
Date: 2012-12-04 23:13:51 EST (Tue, 04 Dec 2012)
New Revision: 81715
URL: http://svn.boost.org/trac/boost/changeset/81715

Log:
Merged revision 81463 from trunk:
Update shared_ptr casts.
........

Added:
   branches/release/libs/smart_ptr/test/sp_array_cast_test.cpp
      - copied unchanged from r81463, /trunk/libs/smart_ptr/test/sp_array_cast_test.cpp
Properties modified:
   branches/release/ (props changed)
   branches/release/boost/ (props changed)
   branches/release/boost/smart_ptr/ (props changed)
   branches/release/libs/ (props changed)
   branches/release/libs/smart_ptr/ (props changed)
Text files modified:
   branches/release/boost/smart_ptr/shared_ptr.hpp | 81 +++++++++++----------------------------
   branches/release/libs/smart_ptr/test/Jamfile.v2 | 1
   2 files changed, 25 insertions(+), 57 deletions(-)

Modified: branches/release/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- branches/release/boost/smart_ptr/shared_ptr.hpp (original)
+++ branches/release/boost/smart_ptr/shared_ptr.hpp 2012-12-04 23:13:51 EST (Tue, 04 Dec 2012)
@@ -62,11 +62,6 @@
 namespace detail
 {
 
-struct static_cast_tag {};
-struct const_cast_tag {};
-struct dynamic_cast_tag {};
-struct polymorphic_cast_tag {};
-
 // sp_element, element_type
 
 template< class T > struct sp_element
@@ -420,36 +415,6 @@
     {
     }
 
- template<class Y>
- shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag)
- BOOST_NOEXCEPT : 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)
- BOOST_NOEXCEPT : 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>
@@ -723,42 +688,44 @@
     a.swap(b);
 }
 
-template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> static_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
 {
- return shared_ptr<T>(r, boost::detail::static_cast_tag());
-}
+ (void) static_cast< T* >( static_cast< U* >( 0 ) );
 
-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());
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = static_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
 }
 
-template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> const_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
 {
- return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
-}
+ (void) const_cast< T* >( static_cast< U* >( 0 ) );
 
-// shared_*_cast names are deprecated. Use *_pointer_cast instead.
+ typedef typename shared_ptr<T>::element_type E;
 
-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());
+ E * p = const_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
 }
 
-template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> dynamic_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
 {
- return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
-}
+ (void) dynamic_cast< T* >( static_cast< U* >( 0 ) );
 
-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());
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = dynamic_cast< E* >( r.get() );
+ return p? shared_ptr<T>( r, p ): shared_ptr<T>();
 }
 
-template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
+template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U> const & r ) BOOST_NOEXCEPT
 {
- BOOST_ASSERT(dynamic_cast<T *>(r.get()) == r.get());
- return shared_static_cast<T>(r);
+ (void) reinterpret_cast< T* >( static_cast< U* >( 0 ) );
+
+ typedef typename shared_ptr<T>::element_type E;
+
+ E * p = reinterpret_cast< E* >( r.get() );
+ return shared_ptr<T>( r, p );
 }
 
 // get_pointer() enables boost::mem_fn to recognize shared_ptr

Modified: branches/release/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- branches/release/libs/smart_ptr/test/Jamfile.v2 (original)
+++ branches/release/libs/smart_ptr/test/Jamfile.v2 2012-12-04 23:13:51 EST (Tue, 04 Dec 2012)
@@ -74,6 +74,7 @@
           [ compile sp_array_cv_test.cpp ]
           [ run sp_convertible_test.cpp ]
           [ run sp_array_n_test.cpp ]
+ [ run sp_array_cast_test.cpp ]
 
           [ compile-fail array_fail_spa_sp_c.cpp ]
           [ compile-fail array_fail_sp_spa_c.cpp ]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk