Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54939 - sandbox/fmhess/boost/smart_ptr
From: fmhess_at_[hidden]
Date: 2009-07-13 18:13:34


Author: fmhess
Date: 2009-07-13 18:13:33 EDT (Mon, 13 Jul 2009)
New Revision: 54939
URL: http://svn.boost.org/trac/boost/changeset/54939

Log:
Modified shared_ptr (renamed to generic_shared) to support smart pointers
as the pointer type. Reimplemented shared_ptr in terms of generic_shared
in order to run shared_ptr tests. Support for weak_ptr and enable_shared_from_this
does not yet exist.

Added:
   sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp (contents, props changed)
Text files modified:
   sandbox/fmhess/boost/smart_ptr/generic_shared.hpp | 387 ++++++++++++++++++++++-----------------
   1 files changed, 218 insertions(+), 169 deletions(-)

Modified: sandbox/fmhess/boost/smart_ptr/generic_shared.hpp
==============================================================================
--- sandbox/fmhess/boost/smart_ptr/generic_shared.hpp (original)
+++ sandbox/fmhess/boost/smart_ptr/generic_shared.hpp 2009-07-13 18:13:33 EDT (Mon, 13 Jul 2009)
@@ -1,33 +1,42 @@
-#ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
-#define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+#ifndef BOOST_SMART_PTR_GENERIC_SHARED_HPP_INCLUDED
+#define BOOST_SMART_PTR_GENERIC_SHARED_HPP_INCLUDED
 
 //
-// shared_ptr.hpp
+// generic_shared.hpp
 //
 // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999.
 // Copyright (c) 2001-2008 Peter Dimov
+// Copyright (c) 2009 Frank Mori Hess
 //
 // 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.
+// See http://www.boost.org/libs/smart_ptr/generic_shared.htm for documentation.
 //
 
+// requirements for generic pointer type:
+// Must be either ordinary pointer, or provide:
+// value_type/reference/pointer member typedefs and a null_value member constant (or specialization of boost::smart_pointer_traits)
+// (in)equality comparison
+// static/const/dynamic_pointer_cast support (if you want support for casting)
+
 #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>
+#include <boost/smart_ptr/detail/generic_shared_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
+// 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/get_pointer.hpp>
+#include <boost/pointer_cast.hpp>
 #include <boost/throw_exception.hpp>
 #include <boost/smart_ptr/detail/shared_count.hpp>
 #include <boost/detail/workaround.hpp>
@@ -58,87 +67,77 @@
 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;
+template<class T> class generic_shared;
 
-namespace detail
+template<class T> struct smart_pointer_traits
 {
+ typedef typename T::value_type value_type;
+ typedef typename T::pointer pointer;
+ typedef typename T::reference reference;
+ static const pointer null_value;
+};
+template<class T>
+const typename smart_pointer_traits<T>::pointer smart_pointer_traits<T>::null_value = T::null_value;
 
-struct static_cast_tag {};
-struct const_cast_tag {};
-struct dynamic_cast_tag {};
-struct polymorphic_cast_tag {};
-
-template<class T> struct shared_ptr_traits
+template<class T> struct smart_pointer_traits<T*>
 {
+ typedef T value_type;
+ typedef T * pointer;
     typedef T & reference;
+ static const pointer null_value;
 };
+template<class T>
+T * const smart_pointer_traits<T*>::null_value = 0;
 
-template<> struct shared_ptr_traits<void>
+template<> struct smart_pointer_traits<void*>
 {
+ typedef void value_type;
+ typedef void * pointer;
     typedef void reference;
+ static const pointer null_value;
 };
+void * const smart_pointer_traits<void*>::null_value = 0;
 
-#if !defined(BOOST_NO_CV_VOID_SPECIALIZATIONS)
-
-template<> struct shared_ptr_traits<void const>
+template<> struct smart_pointer_traits<const void*>
 {
+ typedef void value_type;
+ typedef const void * pointer;
     typedef void reference;
+ static const pointer null_value;
 };
+const void * const smart_pointer_traits<const void*>::null_value = 0;
 
-template<> struct shared_ptr_traits<void volatile>
+template<> struct smart_pointer_traits<volatile void*>
 {
+ typedef void value_type;
+ typedef volatile void * pointer;
     typedef void reference;
+ static const pointer null_value;
 };
+volatile void * const smart_pointer_traits<volatile void*>::null_value = 0;
 
-template<> struct shared_ptr_traits<void const volatile>
+template<> struct smart_pointer_traits<const volatile void*>
 {
+ typedef void value_type;
+ typedef const volatile void * pointer;
     typedef void reference;
+ static const pointer null_value;
 };
+const volatile void * const smart_pointer_traits<const volatile void*>::null_value = 0;
 
-#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 )
+namespace gs_detail
 {
-}
 
-#else // _MANAGED
+struct static_cast_tag {};
+struct const_cast_tag {};
+struct dynamic_cast_tag {};
+struct polymorphic_cast_tag {};
 
-inline void sp_enable_shared_from_this( ... )
+template<typename T, typename U, typename V>
+inline void sp_enable_shared_from_this(T, U, V)
 {
 }
 
-#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
@@ -150,89 +149,79 @@
 template< class T, class R > struct sp_enable_if_auto_ptr< std::auto_ptr< T >, R >
 {
     typedef R type;
-};
+};
 
 #endif
 
-} // namespace detail
+template<typename Y, typename T>
+class sp_enable_if_convertible: public
+ detail::sp_enable_if_convertible<typename smart_pointer_traits<Y>::value_type, typename smart_pointer_traits<T>::value_type>
+{};
+
+} // namespace gs_detail
 
 
 //
-// shared_ptr
+// generic_shared
 //
 // 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
+// The object pointed to is deleted when the last generic_shared pointing to it
 // is destroyed or reset.
 //
 
-template<class T> class shared_ptr
+template<class T> class generic_shared
 {
 private:
 
     // Borland 5.5.1 specific workaround
- typedef shared_ptr<T> this_type;
+ typedef generic_shared<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;
+ typedef typename boost::smart_pointer_traits<T>::value_type element_type;
+ typedef typename boost::smart_pointer_traits<T>::value_type value_type;
+ typedef T pointer;
+ typedef typename boost::smart_pointer_traits<T>::reference reference;
+ static const pointer null_value;
 
- shared_ptr(): px(0), pn() // never throws in 1.30+
+ generic_shared(): px(), pn()
     {
     }
 
     template<class Y>
- explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
+ explicit generic_shared( Y p ): px( p ), pn( p ) // Y must be complete
     {
- boost::detail::sp_enable_shared_from_this( this, p, p );
+ boost::gs_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)
+ // generic_shared will release p by calling d(p)
     //
 
- template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
+ template<class Y, class D> generic_shared(Y p, D d): px(p), pn(p, d)
     {
- boost::detail::sp_enable_shared_from_this( this, p, p );
+ boost::gs_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 )
+ template<class Y, class D, class A> generic_shared( Y p, D d, A a ): px( p ), pn( p, d, a )
     {
- boost::detail::sp_enable_shared_from_this( this, p, p );
+ boost::gs_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() )
+ generic_shared( generic_shared<Y> const & r, typename gs_detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
 
 #else
 
- shared_ptr( shared_ptr<Y> const & r )
+ generic_shared( generic_shared<Y> const & r )
 
 #endif
     : px( r.px ), pn( r.pn ) // never throws
@@ -241,33 +230,33 @@
 
     // aliasing
     template< class Y >
- shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws
+ generic_shared( generic_shared<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)
+ generic_shared(generic_shared<Y> const & r, boost::gs_detail::static_cast_tag): px(static_pointer_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)
+ generic_shared(generic_shared<Y> const & r, boost::gs_detail::const_cast_tag): px(const_pointer_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)
+ generic_shared(generic_shared<Y> const & r, boost::gs_detail::dynamic_cast_tag): px(dynamic_pointer_cast<element_type>(r.px)), pn(r.pn)
     {
- if(px == 0) // need to allocate new counter -- the cast failed
+ if(px == null_value) // 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)
+ generic_shared(generic_shared<Y> const & r, boost::gs_detail::polymorphic_cast_tag): px(dynamic_pointer_cast<element_type>(r.px)), pn(r.pn)
     {
- if(px == 0)
+ if(px == null_value)
         {
             boost::throw_exception(std::bad_cast());
         }
@@ -276,21 +265,21 @@
 #ifndef BOOST_NO_AUTO_PTR
 
     template<class Y>
- explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
+ explicit generic_shared(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 );
+ boost::gs_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()
+ explicit generic_shared( Ap r, typename boost::gs_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 );
+ boost::gs_detail::sp_enable_shared_from_this( this, tmp, tmp );
     }
 
 
@@ -300,7 +289,7 @@
 
     // assignment
 
- shared_ptr & operator=( shared_ptr const & r ) // never throws
+ generic_shared & operator=( generic_shared const & r ) // never throws
     {
         this_type(r).swap(*this);
         return *this;
@@ -309,7 +298,7 @@
 #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
 
     template<class Y>
- shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
+ generic_shared & operator=(generic_shared<Y> const & r) // never throws
     {
         this_type(r).swap(*this);
         return *this;
@@ -320,7 +309,7 @@
 #ifndef BOOST_NO_AUTO_PTR
 
     template<class Y>
- shared_ptr & operator=( std::auto_ptr<Y> & r )
+ generic_shared & operator=( std::auto_ptr<Y> & r )
     {
         this_type(r).swap(*this);
         return *this;
@@ -329,7 +318,7 @@
 #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 )
+ typename boost::gs_detail::sp_enable_if_auto_ptr< Ap, generic_shared & >::type operator=( Ap r )
     {
         this_type( r ).swap( *this );
         return *this;
@@ -344,36 +333,36 @@
 
 #if defined( BOOST_HAS_RVALUE_REFS )
 
- shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws
+ generic_shared( generic_shared && r ): px( r.px ), pn() // never throws
     {
         pn.swap( r.pn );
- r.px = 0;
+ r.px = null_value;
     }
 
     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() )
+ generic_shared( generic_shared<Y> && r, typename gs_detail::sp_enable_if_convertible<Y,T>::type = detail::sp_empty() )
 
 #else
 
- shared_ptr( shared_ptr<Y> && r )
+ generic_shared( generic_shared<Y> && r )
 
 #endif
     : px( r.px ), pn() // never throws
     {
         pn.swap( r.pn );
- r.px = 0;
+ r.px = null_value;
     }
 
- shared_ptr & operator=( shared_ptr && r ) // never throws
+ generic_shared & operator=( generic_shared && r ) // never throws
     {
         this_type( std::move( r ) ).swap( *this );
         return *this;
     }
 
     template<class Y>
- shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
+ generic_shared & operator=( generic_shared<Y> && r ) // never throws
     {
         this_type( std::move( r ) ).swap( *this );
         return *this;
@@ -386,46 +375,105 @@
         this_type().swap(*this);
     }
 
- template<class Y> void reset(Y * p) // Y must be complete
+ template<class Y> void reset(Y p) // Y must be complete
     {
- BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
+ BOOST_ASSERT(p == null_value || p != px); // catch self-reset errors
         this_type(p).swap(*this);
     }
 
- template<class Y, class D> void reset( Y * p, D d )
+ 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 )
+ 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 )
+ template<class Y> void reset( generic_shared<Y> const & r, T p )
     {
         this_type( r, p ).swap( *this );
     }
 
     reference operator* () const // never throws
     {
- BOOST_ASSERT(px != 0);
+ BOOST_ASSERT(px != null_value);
         return *px;
     }
 
- T * operator-> () const // never throws
+ pointer operator-> () const // never throws
     {
- BOOST_ASSERT(px != 0);
+ BOOST_ASSERT(px != null_value);
         return px;
     }
 
- T * get() const // never throws
+ pointer get() const // never throws
     {
         return px;
     }
 
 // implicit conversion to "bool"
-#include <boost/smart_ptr/detail/operator_bool.hpp>
+#if 0
+#include <boost/smart_ptr/detail/generic_operator_bool.hpp>
+#else
+// This header intentionally has no include guards.
+//
+// Copyright (c) 2001-2009 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
+
+#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__)
+
+ operator bool () const
+ {
+ return px != null_value;
+ }
+
+#elif defined( _MANAGED )
+
+ static void unspecified_bool( this_type*** )
+ {
+ }
+
+ typedef void (*unspecified_bool_type)( this_type*** );
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return px == null_value? 0: unspecified_bool;
+ }
+
+#elif \
+ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \
+ ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \
+ ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) )
+
+ typedef T (this_type::*unspecified_bool_type)() const;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return px == null_value? 0: &this_type::get;
+ }
+
+#else
+
+ typedef T this_type::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const // never throws
+ {
+ return px == null_value? 0: &this_type::px;
+ }
+
+#endif
+
+ // operator! is redundant, but some compilers need it
+ bool operator! () const // never throws
+ {
+ return px == null_value;
+ }
+#endif // end implicit conversion to "bool" support
 
     bool unique() const // never throws
     {
@@ -437,13 +485,13 @@
         return pn.use_count();
     }
 
- void swap(shared_ptr<T> & other) // never throws
+ void swap(generic_shared<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
+ template<class Y> bool _internal_less(generic_shared<Y> const & rhs) const
     {
         return pn < rhs.pn;
     }
@@ -453,7 +501,7 @@
         return pn.get_deleter( ti );
     }
 
- bool _internal_equiv( shared_ptr const & r ) const
+ bool _internal_equiv( generic_shared const & r ) const
     {
         return px == r.px && pn == r.pn;
     }
@@ -465,23 +513,25 @@
 
 private:
 
- template<class Y> friend class shared_ptr;
+ template<class Y> friend class generic_shared;
     template<class Y> friend class weak_ptr;
 
 
 #endif
 
- T * px; // contained pointer
+ T px; // contained pointer
     boost::detail::shared_count pn; // reference counter
 
-}; // shared_ptr
+}; // generic_shared
+template<typename T>
+const typename generic_shared<T>::pointer generic_shared<T>::null_value = boost::smart_pointer_traits<T>::null_value;
 
-template<class T, class U> inline bool operator==(shared_ptr<T> const & a, shared_ptr<U> const & b)
+template<class T, class U> inline bool operator==(generic_shared<T> const & a, generic_shared<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)
+template<class T, class U> inline bool operator!=(generic_shared<T> const & a, generic_shared<U> const & b)
 {
     return a.get() != b.get();
 }
@@ -490,64 +540,63 @@
 
 // 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)
+template<class T> inline bool operator!=(generic_shared<T> const & a, generic_shared<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)
+template<class T, class U> inline bool operator<(generic_shared<T> const & a, generic_shared<U> const & b)
 {
     return a._internal_less(b);
 }
 
-template<class T> inline void swap(shared_ptr<T> & a, shared_ptr<T> & b)
+template<class T> inline void swap(generic_shared<T> & a, generic_shared<T> & b)
 {
     a.swap(b);
 }
 
-template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> static_pointer_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::static_cast_tag());
+ return generic_shared<T>(r, boost::gs_detail::static_cast_tag());
 }
 
-template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> const_pointer_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::const_cast_tag());
+ return generic_shared<T>(r, boost::gs_detail::const_cast_tag());
 }
 
-template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> dynamic_pointer_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
+ return generic_shared<T>(r, boost::gs_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)
+template<class T, class U> generic_shared<T> shared_static_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::static_cast_tag());
+ return generic_shared<T>(r, boost::gs_detail::static_cast_tag());
 }
 
-template<class T, class U> shared_ptr<T> shared_dynamic_cast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> shared_dynamic_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::dynamic_cast_tag());
+ return generic_shared<T>(r, boost::gs_detail::dynamic_cast_tag());
 }
 
-template<class T, class U> shared_ptr<T> shared_polymorphic_cast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> shared_polymorphic_cast(generic_shared<U> const & r)
 {
- return shared_ptr<T>(r, boost::detail::polymorphic_cast_tag());
+ return generic_shared<T>(r, boost::gs_detail::polymorphic_cast_tag());
 }
 
-template<class T, class U> shared_ptr<T> shared_polymorphic_downcast(shared_ptr<U> const & r)
+template<class T, class U> generic_shared<T> shared_polymorphic_downcast(generic_shared<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)
+// get_pointer() enables boost::mem_fn to recognize generic_shared
+template<class T> inline T get_pointer(generic_shared<T> const & p)
 {
     return p.get();
 }
@@ -558,7 +607,7 @@
 
 #if defined(BOOST_NO_TEMPLATED_IOSTREAMS) || ( defined(__GNUC__) && (__GNUC__ < 3) )
 
-template<class Y> std::ostream & operator<< (std::ostream & os, shared_ptr<Y> const & p)
+template<class Y> std::ostream & operator<< (std::ostream & os, generic_shared<Y> const & p)
 {
     os << p.get();
     return os;
@@ -572,9 +621,9 @@
 # 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)
+template<class E, class T, class Y> basic_ostream<E, T> & operator<< (basic_ostream<E, T> & os, generic_shared<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)
+template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, generic_shared<Y> const & p)
 # endif
 {
     os << p.get();
@@ -596,7 +645,7 @@
 // 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)
+template<class D, class T> D * get_deleter(generic_shared<T> const & p)
 {
     void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D));
     return const_cast<D *>(static_cast<D const *>(q));
@@ -604,7 +653,7 @@
 
 #else
 
-template<class D, class T> D * get_deleter(shared_ptr<T> const & p)
+template<class D, class T> D * get_deleter(generic_shared<T> const & p)
 {
     return static_cast<D *>(p._internal_get_deleter(BOOST_SP_TYPEID(D)));
 }
@@ -615,34 +664,34 @@
 
 #if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
 
-template<class T> inline bool atomic_is_lock_free( shared_ptr<T> const * /*p*/ )
+template<class T> inline bool atomic_is_lock_free( generic_shared<T> const * /*p*/ )
 {
     return false;
 }
 
-template<class T> shared_ptr<T> atomic_load( shared_ptr<T> const * p )
+template<class T> generic_shared<T> atomic_load( generic_shared<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*/ )
+template<class T> inline generic_shared<T> atomic_load_explicit( generic_shared<T> const * p, memory_order /*mo*/ )
 {
     return atomic_load( p );
 }
 
-template<class T> void atomic_store( shared_ptr<T> * p, shared_ptr<T> r )
+template<class T> void atomic_store( generic_shared<T> * p, generic_shared<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*/ )
+template<class T> inline void atomic_store_explicit( generic_shared<T> * p, generic_shared<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 )
+template<class T> generic_shared<T> atomic_exchange( generic_shared<T> * p, generic_shared<T> r )
 {
     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
 
@@ -653,12 +702,12 @@
     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*/ )
+template<class T> generic_shared<T> atomic_exchange_explicit( generic_shared<T> * p, generic_shared<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 )
+template<class T> bool atomic_compare_exchange( generic_shared<T> * p, generic_shared<T> * v, generic_shared<T> w )
 {
     boost::detail::spinlock & sp = boost::detail::spinlock_pool<2>::spinlock_for( p );
 
@@ -674,7 +723,7 @@
     }
     else
     {
- shared_ptr<T> tmp( *p );
+ generic_shared<T> tmp( *p );
 
         sp.unlock();
 
@@ -683,7 +732,7 @@
     }
 }
 
-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*/ )
+template<class T> inline bool atomic_compare_exchange_explicit( generic_shared<T> * p, generic_shared<T> * v, generic_shared<T> w, memory_order /*success*/, memory_order /*failure*/ )
 {
     return atomic_compare_exchange( p, v, w ); // std::move( w )
 }
@@ -698,4 +747,4 @@
 
 #endif // #if defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(BOOST_MSVC6_MEMBER_TEMPLATES)
 
-#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+#endif // #ifndef BOOST_SMART_PTR_SHARED_HPP_INCLUDED

Added: sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/fmhess/boost/smart_ptr/shared_ptr.hpp 2009-07-13 18:13:33 EDT (Mon, 13 Jul 2009)
@@ -0,0 +1,126 @@
+#ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+#define BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED
+
+// Implementation of shared_ptr as wrapper around generic_shared.
+// Written primarily to help test generic_shared using unmodified
+// shared_ptr tests.
+
+// Copyright (c) 2009 Frank Mori Hess
+//
+// 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)
+
+#include <boost/smart_ptr/generic_shared.hpp>
+
+namespace boost
+{
+ namespace detail
+ {
+ template<typename T, typename U, typename V>
+ inline void sp_enable_shared_from_this(T, U, V)
+ {
+ }
+ }
+
+ template<typename T>
+ class shared_ptr: public generic_shared<T*>
+ {
+ typedef generic_shared<T*> base_type;
+ public:
+ shared_ptr(const base_type &base): base_type(base)
+ {}
+ shared_ptr() {}
+ template<typename U>
+ explicit shared_ptr(U *u): base_type(u)
+ {}
+ template<typename U, typename V>
+ shared_ptr(U *u, V v): base_type(u, v)
+ {}
+ template<typename U, typename V, typename W>
+ shared_ptr(U *u, V v, W w): base_type(u, v, w)
+ {}
+ template<class Y>
+#if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
+ shared_ptr( shared_ptr<Y> const & r, typename gs_detail::sp_enable_if_convertible<Y*,T*>::type = detail::sp_empty() )
+#else
+ shared_ptr( shared_ptr<Y> const & r )
+#endif
+ : base_type(static_cast<generic_shared<Y*> const &>(r))
+ {}
+ template<typename Y>
+ shared_ptr(shared_ptr<Y> const & r, T *p): base_type(static_cast<const generic_shared<Y*> &>(r), p)
+ {}
+ template<typename Y>
+ shared_ptr(shared_ptr<Y> const & r, boost::gs_detail::static_cast_tag t): base_type(static_cast<const generic_shared<Y*> &>(r), t)
+ {}
+ template<typename Y>
+ shared_ptr(shared_ptr<Y> const & r, boost::gs_detail::const_cast_tag t): base_type(static_cast<const generic_shared<Y*> &>(r), t)
+ {}
+ template<typename Y>
+ shared_ptr(shared_ptr<Y> const & r, boost::gs_detail::dynamic_cast_tag t): base_type(static_cast<const generic_shared<Y*> &>(r), t)
+ {}
+ template<typename Y>
+ explicit shared_ptr(std::auto_ptr<Y> & r): base_type(r)
+ {}
+ template<typename Ap>
+ explicit shared_ptr( Ap r): base_type(r)
+ {}
+ template<typename Y>
+ shared_ptr & operator=( std::auto_ptr<Y> & r )
+ {
+ return static_cast<shared_ptr&>(static_cast<base_type&>(*this) = r);
+ }
+#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
+ template<typename Ap>
+ typename boost::gs_detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
+ {
+ return static_cast<shared_ptr&>(static_cast<base_type&>(*this) = r);
+ }
+#endif // BOOST_NO_SFINAE, BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+ shared_ptr & operator=( shared_ptr const & r )
+ {
+ return static_cast<shared_ptr&>(static_cast<base_type&>(*this) = r);
+ }
+#if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1400)
+ template<class Y>
+ shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
+ {
+ return static_cast<shared_ptr&>(static_cast<base_type&>(*this) = static_cast<const generic_shared<Y*> &>(r));
+ }
+#endif
+ void reset() { base_type::reset(); }
+ template<class Y> void reset(Y *p) // Y must be complete
+ {
+ base_type::reset(p);
+ }
+ template<class Y, class D> void reset( Y *p, D d )
+ {
+ base_type::reset(p, d);
+ }
+ template<class Y, class D, class A> void reset( Y *p, D d, A a )
+ {
+ base_type::reset(p, d, a);
+ }
+ template<typename Y> void reset( shared_ptr<Y> const & r, T *p )
+ {
+ base_type::reset(static_cast<generic_shared<Y*> const &>(r), p);
+ }
+ };
+ template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U> const & r)
+ {
+ return shared_ptr<T>(r, boost::gs_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::gs_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::gs_detail::dynamic_cast_tag());
+ }
+}
+
+#endif // #ifndef BOOST_SMART_PTR_SHARED_PTR_HPP_INCLUDED


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