Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54387 - in trunk/boost/ptr_container: . detail
From: nesotto_at_[hidden]
Date: 2009-06-26 19:34:50


Author: nesotto
Date: 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
New Revision: 54387
URL: http://svn.boost.org/trac/boost/changeset/54387

Log:
added support for statefull clone_allocators
Text files modified:
   trunk/boost/ptr_container/detail/reversible_ptr_container.hpp | 202 +++++++++++++++++++++------------------
   trunk/boost/ptr_container/detail/scoped_deleter.hpp | 39 ++++--
   trunk/boost/ptr_container/detail/static_move_ptr.hpp | 12 -
   trunk/boost/ptr_container/ptr_array.hpp | 20 +--
   trunk/boost/ptr_container/ptr_circular_buffer.hpp | 34 +++---
   trunk/boost/ptr_container/ptr_inserter.hpp | 27 +---
   trunk/boost/ptr_container/ptr_map_adapter.hpp | 25 ++--
   trunk/boost/ptr_container/ptr_sequence_adapter.hpp | 14 +-
   trunk/boost/ptr_container/ptr_set_adapter.hpp | 10
   9 files changed, 197 insertions(+), 186 deletions(-)

Modified: trunk/boost/ptr_container/detail/reversible_ptr_container.hpp
==============================================================================
--- trunk/boost/ptr_container/detail/reversible_ptr_container.hpp (original)
+++ trunk/boost/ptr_container/detail/reversible_ptr_container.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -35,6 +35,7 @@
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_pointer.hpp>
 #include <boost/type_traits/is_integral.hpp>
+#include <boost/swap.hpp>
 #include <typeinfo>
 #include <memory>
 
@@ -49,12 +50,32 @@
 
 namespace ptr_container_detail
 {
+ template< class Container >
+ struct dynamic_clone_deleter
+ {
+ dynamic_clone_deleter() { }
+ dynamic_clone_deleter( Container& cont ) : cont(&cont) { }
+ Container* cont;
+
+ template< class T >
+ void operator()( const T* p ) const
+ {
+ // remark: static_move_ptr already test for null
+ cont->get_clone_allocator().deallocate_clone( p );
+ }
+ };
+
     template< class CloneAllocator >
- struct clone_deleter
+ struct static_clone_deleter
     {
+ static_clone_deleter() { }
+ template< class Dummy >
+ static_clone_deleter( const Dummy& ) { }
+
         template< class T >
         void operator()( const T* p ) const
         {
+ // remark: static_move_ptr already test for null
             CloneAllocator::deallocate_clone( p );
         }
     };
@@ -80,71 +101,26 @@
         class Config,
         class CloneAllocator
>
- class reversible_ptr_container
+ class reversible_ptr_container : CloneAllocator
     {
     private:
         BOOST_STATIC_CONSTANT( bool, allow_null = Config::allow_null );
-
- typedef BOOST_DEDUCED_TYPENAME Config::value_type Ty_;
-
- template< bool allow_null_values >
- struct null_clone_allocator
- {
- template< class Iter >
- static Ty_* allocate_clone_from_iterator( Iter i )
- {
- return allocate_clone( Config::get_const_pointer( i ) );
- }
-
- static Ty_* allocate_clone( const Ty_* x )
- {
- if( allow_null_values )
- {
- if( x == 0 )
- return 0;
- }
- else
- {
- BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
- }
-
- Ty_* res = CloneAllocator::allocate_clone( *x );
- BOOST_ASSERT( typeid(*res) == typeid(*x) &&
- "CloneAllocator::allocate_clone() does not clone the "
- "object properly. Check that new_clone() is implemented"
- " correctly" );
- return res;
- }
-
- static void deallocate_clone( const Ty_* x )
- {
- if( allow_null_values )
- {
- if( x == 0 )
- return;
- }
+ BOOST_STATIC_CONSTANT( bool, is_clone_allocator_empty = sizeof(CloneAllocator) < sizeof(void*) );
 
- CloneAllocator::deallocate_clone( x );
- }
- };
-
- typedef BOOST_DEDUCED_TYPENAME Config::void_container_type Cont;
-#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
- typedef null_clone_allocator<reversible_ptr_container::allow_null>
- null_cloner_type;
-#else
- typedef null_clone_allocator<allow_null> null_cloner_type;
-#endif
- typedef clone_deleter<null_cloner_type> Deleter;
-
- Cont c_;
+ typedef BOOST_DEDUCED_TYPENAME Config::value_type Ty_;
+ typedef BOOST_DEDUCED_TYPENAME Config::void_container_type container_type;
+ typedef dynamic_clone_deleter<reversible_ptr_container> dynamic_deleter_type;
+ typedef static_clone_deleter<CloneAllocator> static_deleter_type;
+
+ container_type c_;
 
     public:
- Cont& base() { return c_; }
+ container_type& base() { return c_; }
     protected: // having this public could break encapsulation
- const Cont& base() const { return c_; }
+ const container_type& base() const { return c_; }
         
     public: // typedefs
+ typedef Ty_ object_type;
         typedef Ty_* value_type;
         typedef Ty_* pointer;
         typedef Ty_& reference;
@@ -158,23 +134,27 @@
                                    reverse_iterator;
         typedef boost::reverse_iterator< const_iterator >
                                    const_reverse_iterator;
- typedef BOOST_DEDUCED_TYPENAME Cont::difference_type
+ typedef BOOST_DEDUCED_TYPENAME container_type::difference_type
                                    difference_type;
- typedef BOOST_DEDUCED_TYPENAME Cont::size_type
+ typedef BOOST_DEDUCED_TYPENAME container_type::size_type
                                    size_type;
         typedef BOOST_DEDUCED_TYPENAME Config::allocator_type
                                    allocator_type;
         typedef CloneAllocator clone_allocator_type;
- typedef ptr_container_detail::static_move_ptr<Ty_,Deleter>
+ typedef ptr_container_detail::static_move_ptr<Ty_,
+ BOOST_DEDUCED_TYPENAME boost::mpl::if_c<is_clone_allocator_empty,
+ static_deleter_type,
+ dynamic_deleter_type>::type
+ >
                                    auto_type;
             
     protected:
             
- typedef ptr_container_detail::scoped_deleter<Ty_,null_cloner_type>
+ typedef ptr_container_detail::scoped_deleter<reversible_ptr_container>
                                    scoped_deleter;
- typedef BOOST_DEDUCED_TYPENAME Cont::iterator
+ typedef BOOST_DEDUCED_TYPENAME container_type::iterator
                                    ptr_iterator;
- typedef BOOST_DEDUCED_TYPENAME Cont::const_iterator
+ typedef BOOST_DEDUCED_TYPENAME container_type::const_iterator
                                    ptr_const_iterator;
     private:
 
@@ -186,7 +166,7 @@
         
         void copy( const reversible_ptr_container& r )
         {
- copy( r.begin(), r.end() );
+ this->copy( r.begin(), r.end() );
         }
         
         void copy_clones_and_release( scoped_deleter& sd ) // nothrow
@@ -201,8 +181,8 @@
                            ForwardIterator last ) // strong
         {
             BOOST_ASSERT( first != last );
- scoped_deleter sd( first, last ); // strong
- copy_clones_and_release( sd ); // nothrow
+ scoped_deleter sd( *this, first, last ); // strong
+ copy_clones_and_release( sd ); // nothrow
         }
 
         template< class ForwardIterator >
@@ -210,13 +190,13 @@
                                 ForwardIterator last )
         {
             BOOST_ASSERT( first != last );
- scoped_deleter sd( first, last );
+ scoped_deleter sd( *this, first, last );
             insert_clones_and_release( sd, end() );
         }
         
         void remove_all()
         {
- remove( begin(), end() );
+ this->remove( begin(), end() );
         }
 
     protected:
@@ -242,20 +222,20 @@
         template< class U >
         void remove( U* ptr )
         {
- null_policy_deallocate_clone( ptr );
+ this->deallocate_clone( ptr );
         }
         
         template< class I >
         void remove( I i )
         {
- null_policy_deallocate_clone( Config::get_const_pointer(i) );
+ this->deallocate_clone( Config::get_const_pointer(i) );
         }
 
         template< class I >
         void remove( I first, I last )
         {
             for( ; first != last; ++first )
- remove( first );
+ this->remove( first );
         }
 
         static void enforce_null_policy( const Ty_* x, const char* msg )
@@ -267,16 +247,44 @@
             }
         }
 
- static Ty_* null_policy_allocate_clone( const Ty_* x )
+ public:
+ Ty_* null_policy_allocate_clone( const Ty_* x )
         {
- return null_cloner_type::allocate_clone( x );
+ if( allow_null )
+ {
+ if( x == 0 )
+ return 0;
+ }
+ else
+ {
+ BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
+ }
+
+ Ty_* res = this->get_clone_allocator().allocate_clone( *x );
+ BOOST_ASSERT( typeid(*res) == typeid(*x) &&
+ "CloneAllocator::allocate_clone() does not clone the "
+ "object properly. Check that new_clone() is implemented"
+ " correctly" );
+ return res;
         }
 
- static void null_policy_deallocate_clone( const Ty_* x )
+ template< class Iterator >
+ Ty_* null_policy_allocate_clone_from_iterator( Iterator i )
         {
- null_cloner_type::deallocate_clone( x );
+ return this->null_policy_allocate_clone(Config::get_const_pointer(i));
         }
+
+ void null_policy_deallocate_clone( const Ty_* x )
+ {
+ if( allow_null )
+ {
+ if( x == 0 )
+ return;
+ }
 
+ this->get_clone_allocator().deallocate_clone( x );
+ }
+
     private:
         template< class ForwardIterator >
         ForwardIterator advance( ForwardIterator begin, size_type n )
@@ -291,7 +299,7 @@
         {
             while( first != last )
             {
- insert( end(), null_cloner_type::allocate_clone_from_iterator(first) );
+ insert( end(), this->allocate_clone_from_iterator(first) );
                 ++first;
             }
         }
@@ -310,11 +318,11 @@
             if( first == last )
                 return;
 
- scoped_deleter sd( first, last );
+ scoped_deleter sd( *this, first, last );
             insert_clones_and_release( sd );
         }
 
- public: // foundation! should be protected!
+ public: // foundation: should be protected, but public for poor compilers' sake.
         reversible_ptr_container()
         { }
 
@@ -472,6 +480,16 @@
         {
             return c_.get_allocator();
         }
+
+ clone_allocator_type& get_clone_allocator()
+ {
+ return static_cast<clone_allocator_type&>(*this);
+ }
+
+ const clone_allocator_type& get_clone_allocator() const
+ {
+ return static_cast<const clone_allocator_type&>(*this);
+ }
  
     public: // container requirements
         iterator begin()
@@ -504,7 +522,8 @@
 
         void swap( reversible_ptr_container& r ) // nothrow
         {
- c_.swap( r.c_ );
+ boost::swap( get_clone_allocator(), r.get_clone_allocator() ); // nothrow
+ c_.swap( r.c_ ); // nothrow
         }
           
         size_type size() const // nothrow
@@ -563,7 +582,7 @@
         {
             enforce_null_policy( x, "Null pointer in 'insert()'" );
 
- auto_type ptr( x ); // nothrow
+ auto_type ptr( x, *this ); // nothrow
             iterator res( c_.insert( before.base(), x ) ); // strong, commit
             ptr.release(); // nothrow
             return res;
@@ -612,23 +631,21 @@
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
                                                  "'release()' on empty container" );
             
- auto_type ptr( Config::get_pointer( where ) ); // nothrow
- c_.erase( where.base() ); // nothrow
+ auto_type ptr( Config::get_pointer(where), *this ); // nothrow
+ c_.erase( where.base() ); // nothrow
             return boost::ptr_container_detail::move( ptr );
         }
 
         auto_type replace( iterator where, Ty_* x ) // strong
         {
             BOOST_ASSERT( where != end() );
+ enforce_null_policy( x, "Null pointer in 'replace()'" );
 
- enforce_null_policy( x, "Null pointer in 'replace()'" );
-
- auto_type ptr( x );
-
+ auto_type ptr( x, *this );
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
                                                  "'replace()' on empty container" );
 
- auto_type old( Config::get_pointer( where ) ); // nothrow
+ auto_type old( Config::get_pointer(where), *this ); // nothrow
             const_cast<void*&>(*where.base()) = ptr.release();
             return boost::ptr_container_detail::move( old );
         }
@@ -641,15 +658,14 @@
 
         auto_type replace( size_type idx, Ty_* x ) // strong
         {
- enforce_null_policy( x, "Null pointer in 'replace()'" );
-
- auto_type ptr( x );
-
+ enforce_null_policy( x, "Null pointer in 'replace()'" );
+
+ auto_type ptr( x, *this );
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= size(), bad_index,
                                                  "'replace()' out of bounds" );
             
- auto_type old( static_cast<Ty_*>( c_[idx] ) ); // nothrow
- c_[idx] = ptr.release(); // nothrow, commit
+ auto_type old( static_cast<Ty_*>(c_[idx]), *this ); // nothrow
+ c_[idx] = ptr.release(); // nothrow, commit
             return boost::ptr_container_detail::move( old );
         }
 

Modified: trunk/boost/ptr_container/detail/scoped_deleter.hpp
==============================================================================
--- trunk/boost/ptr_container/detail/scoped_deleter.hpp (original)
+++ trunk/boost/ptr_container/detail/scoped_deleter.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -25,49 +25,60 @@
 
     namespace ptr_container_detail
     {
- template< class T, class CloneAllocator >
+ template< class Container >
         class scoped_deleter
         {
- typedef std::size_t size_type;
+ typedef BOOST_DEDUCED_TYPENAME Container::size_type size_type;
+ typedef BOOST_DEDUCED_TYPENAME Container::object_type T;
+
+ Container& cont_;
             scoped_array<T*> ptrs_;
             size_type stored_;
             bool released_;
             
         public:
- scoped_deleter( T** a, size_type size )
- : ptrs_( a ), stored_( size ), released_( false )
+ scoped_deleter( Container& cont, T** a, size_type size )
+ : cont_(cont),
+ ptrs_( a ),
+ stored_( size ),
+ released_( false )
             {
                 BOOST_ASSERT( a );
             }
             
- scoped_deleter( size_type size )
- : ptrs_( new T*[size] ), stored_( 0 ),
- released_( false )
+ scoped_deleter( Container& cont, size_type size )
+ : cont_(cont),
+ ptrs_( new T*[size] ),
+ stored_( 0 ),
+ released_( false )
             {
                 BOOST_ASSERT( size > 0 );
             }
 
 
             
- scoped_deleter( size_type n, const T& x ) // strong
- : ptrs_( new T*[n] ), stored_(0),
+ scoped_deleter( Container& cont, size_type n, const T& x ) // strong
+ : cont_(cont),
+ ptrs_( new T*[n] ),
+ stored_(0),
                   released_( false )
             {
                 for( size_type i = 0; i != n; i++ )
- add( CloneAllocator::allocate_clone( &x ) );
+ add( cont_.null_policy_allocate_clone( &x ) );
                 BOOST_ASSERT( stored_ > 0 );
             }
 
 
             
             template< class InputIterator >
- scoped_deleter ( InputIterator first, InputIterator last ) // strong
- : ptrs_( new T*[ std::distance(first,last) ] ),
+ scoped_deleter ( Container& cont, InputIterator first, InputIterator last ) // strong
+ : cont_(cont),
+ ptrs_( new T*[ std::distance(first,last) ] ),
                   stored_(0),
                   released_( false )
             {
                 for( ; first != last; ++first )
- add( CloneAllocator::allocate_clone_from_iterator( first ) );
+ add( cont_.null_policy_allocate_clone_from_iterator( first ) );
                 BOOST_ASSERT( stored_ > 0 );
             }
 
@@ -78,7 +89,7 @@
                 if ( !released_ )
                 {
                     for( size_type i = 0u; i != stored_; ++i )
- CloneAllocator::deallocate_clone( ptrs_[i] );
+ cont_.null_policy_deallocate_clone( ptrs_[i] );
                 }
             }
             

Modified: trunk/boost/ptr_container/detail/static_move_ptr.hpp
==============================================================================
--- trunk/boost/ptr_container/detail/static_move_ptr.hpp (original)
+++ trunk/boost/ptr_container/detail/static_move_ptr.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -76,8 +76,8 @@
             }
     
     template<typename TT>
- explicit static_move_ptr(TT* tt)
- : impl_(tt, Deleter())
+ static_move_ptr(TT* tt, Deleter del)
+ : impl_(tt, del)
         { }
 
         // Destructor
@@ -131,13 +131,7 @@
         }
 
     template<typename TT>
- void reset(TT* tt)
- {
- static_move_ptr(tt).swap(*this);
- }
-
- template<typename TT, typename DD>
- void reset(TT* tt, DD dd)
+ void reset(TT* tt, Deleter dd)
         {
             static_move_ptr(tt, dd).swap(*this);
         }

Modified: trunk/boost/ptr_container/ptr_array.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_array.hpp (original)
+++ trunk/boost/ptr_container/ptr_array.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -127,8 +127,8 @@
             std::auto_ptr<this_type> pa( new this_type );
             for( size_t i = 0; i != N; ++i )
             {
- if( ! is_null(i) )
- pa->replace( i, this->null_policy_allocate_clone( &(*this)[i] ) );
+ if( !this->is_null(i) )
+ pa->replace( i, pa->null_policy_allocate_clone( &(*this)[i] ) );
             }
             return pa;
         }
@@ -151,10 +151,9 @@
             BOOST_STATIC_ASSERT( idx < N );
 
             this->enforce_null_policy( r, "Null pointer in 'ptr_array::replace()'" );
-
- auto_type res( static_cast<U*>( this->base()[idx] ) ); // nothrow
- this->base()[idx] = r; // nothrow
- return boost::ptr_container::move(res); // nothrow
+ auto_type res( static_cast<U*>(this->base()[idx]), *this ); // nothrow
+ this->base()[idx] = r; // nothrow
+ return boost::ptr_container::move(res); // nothrow
         }
 
         template< size_t idx, class V >
@@ -167,14 +166,13 @@
         {
             this->enforce_null_policy( r, "Null pointer in 'ptr_array::replace()'" );
 
- auto_type ptr( r );
-
+ auto_type ptr( r, *this );
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= N, bad_index,
                                                  "'replace()' aout of bounds" );
 
- auto_type res( static_cast<U*>( this->base()[idx] ) ); // nothrow
- this->base()[idx] = ptr.release(); // nothrow
- return boost::ptr_container::move(res); // nothrow
+ auto_type res( static_cast<U*>(this->base()[idx]), *this ); // nothrow
+ this->base()[idx] = ptr.release(); // nothrow
+ return boost::ptr_container::move(res); // nothrow
         }
 
         template< class V >

Modified: trunk/boost/ptr_container/ptr_circular_buffer.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_circular_buffer.hpp (original)
+++ trunk/boost/ptr_container/ptr_circular_buffer.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -264,7 +264,7 @@
         {
             ptr_circular_buffer temp( n );
             for( size_type i = 0u; i != n; ++i )
- temp.push_back( this->null_policy_allocate_clone( to_clone ) );
+ temp.push_back( temp.null_policy_allocate_clone( to_clone ) );
             this->swap( temp );
         }
         
@@ -284,13 +284,13 @@
 
         void push_back( value_type ptr ) // nothrow
         {
- BOOST_ASSERT( capacity() > 0 );
+ BOOST_ASSERT( capacity() > 0 );
             this->enforce_null_policy( ptr, "Null pointer in 'push_back()'" );
          
- auto_type old_ptr;
+ auto_type old_ptr( value_type(), *this );
             if( full() )
- old_ptr.reset( &*this->begin() );
- this->base().push_back( ptr );
+ old_ptr.reset( &*this->begin(), *this );
+ this->base().push_back( ptr );
         }
 
         template< class U >
@@ -304,9 +304,9 @@
             BOOST_ASSERT( capacity() > 0 );
             this->enforce_null_policy( ptr, "Null pointer in 'push_front()'" );
 
- auto_type old_ptr;
+ auto_type old_ptr( value_type(), *this );
             if( full() )
- old_ptr.reset( &*(--this->end()) );
+ old_ptr.reset( &*(--this->end()), *this );
             this->base().push_front( ptr );
         }
 
@@ -321,16 +321,16 @@
             BOOST_ASSERT( capacity() > 0 );
             this->enforce_null_policy( ptr, "Null pointer in 'insert()'" );
 
- auto_type new_ptr( ptr );
+ auto_type new_ptr( ptr, *this );
             iterator b = this->begin();
             if( full() && pos == b )
                 return b;
             
- auto_type old_ptr;
+ new_ptr.release();
+ auto_type old_ptr( value_type(), *this );
             if( full() )
- old_ptr.reset( &*this->begin() );
+ old_ptr.reset( &*this->begin(), *this );
 
- new_ptr.release();
             return this->base().insert( pos.base(), ptr );
         }
 
@@ -364,16 +364,16 @@
             BOOST_ASSERT( capacity() > 0 );
             this->enforce_null_policy( ptr, "Null pointer in 'rinsert()'" );
 
- auto_type new_ptr( ptr );
+ auto_type new_ptr( ptr, *this );
             iterator b = this->end();
             if (full() && pos == b)
                 return b;
-
- auto_type old_ptr;
+
+ new_ptr.release();
+ auto_type old_ptr( value_type(), *this );
             if( full() )
- old_ptr.reset( &this->back() );
+ old_ptr.reset( &this->back(), *this );
 
- new_ptr.release();
             return this->base().rinsert( pos.base(), ptr );
         }
 
@@ -485,7 +485,7 @@
             if( delete_from )
             {
                 BOOST_DEDUCED_TYPENAME base_type::scoped_deleter
- deleter( from, size ); // nothrow
+ deleter( *this, from, size ); // nothrow
                 for( size_type i = 0u; i != size; ++i, ++before )
                     before = insert( before, *(from+i) ); // nothrow
                 deleter.release(); // nothrow

Modified: trunk/boost/ptr_container/ptr_inserter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_inserter.hpp (original)
+++ trunk/boost/ptr_container/ptr_inserter.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -65,10 +65,8 @@
         ptr_back_insert_iterator&
         operator=( typename PtrContainer::value_type r )
         {
- typename PtrContainer::value_type obj = 0;
- if( r != 0 )
- obj = container_type::clone_allocator_type::allocate_clone(*r);
-
+ typename PtrContainer::value_type obj
+ = container->null_policy_allocate_clone(r);
             container->push_back( obj );
             return *this;
         }
@@ -84,8 +82,7 @@
         ptr_back_insert_iterator&
         operator=( typename PtrContainer::const_reference r )
         {
- container->push_back( container_type::clone_allocator_type::
- allocate_clone(r) );
+ container->push_back( container->null_policy_allocate_clone(&r) );
             return *this;
         }
 
@@ -125,10 +122,8 @@
         ptr_front_insert_iterator&
         operator=( typename PtrContainer::value_type r )
         {
- typename PtrContainer::value_type obj = 0;
- if( r != 0 )
- obj = container_type::clone_allocator_type::allocate_clone(*r);
-
+ typename PtrContainer::value_type obj
+ = container->null_policy_allocate_clone(r);
             container->push_front( obj );
             return *this;
         }
@@ -144,8 +139,7 @@
         ptr_front_insert_iterator&
         operator=( typename PtrContainer::const_reference r )
         {
- container->push_front( container_type::clone_allocator_type::
- allocate_clone(r) );
+ container->push_front( container->null_policy_allocate_clone(&r) );
             return *this;
         }
 
@@ -186,9 +180,8 @@
         ptr_insert_iterator&
         operator=( typename PtrContainer::value_type r )
         {
- typename PtrContainer::value_type obj = 0;
- if( r != 0 )
- obj = container_type::clone_allocator_type::allocate_clone(*r);
+ typename PtrContainer::value_type obj =
+ container->null_policy_allocate_clone(r);
 
             iter = container->insert( iter, obj );
             return *this;
@@ -205,8 +198,8 @@
         ptr_insert_iterator&
         operator=( typename PtrContainer::const_reference r )
         {
- iter = container->insert( iter, container_type::clone_allocator_type::
- allocate_clone(r) );
+ iter = container->insert( iter,
+ container->null_policy_allocate_clone(&r) );
             return *this;
         }
 

Modified: trunk/boost/ptr_container/ptr_map_adapter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_map_adapter.hpp (original)
+++ trunk/boost/ptr_container/ptr_map_adapter.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -343,17 +343,15 @@
         auto_type replace( iterator where, mapped_type x ) // strong
         {
             BOOST_ASSERT( where != this->end() );
-
             this->enforce_null_policy( x, "Null pointer in 'replace()'" );
 
- auto_type ptr( x );
-
+ auto_type ptr( x, *this );
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
                                                  bad_ptr_container_operation,
                                                  "'replace()' on empty container" );
 
- auto_type old( where->second ); // nothrow
- where.base()->second = ptr.release(); // nothrow, commit
+ auto_type old( where->second, *this ); // nothrow
+ where.base()->second = ptr.release(); // nothrow, commit
             return boost::ptr_container::move( old );
         }
 
@@ -425,7 +423,7 @@
                 if( this->find( first->first ) == this->end() )
                 {
                     const_reference p = *first.base(); // nothrow
- auto_type ptr( this->null_policy_allocate_clone( p.second ) );
+ auto_type ptr( this->null_policy_allocate_clone(p.second), *this );
                                                            // strong
                     this->safe_insert( p.first,
                                        boost::ptr_container::move( ptr ) );
@@ -522,8 +520,8 @@
         std::pair<iterator,bool> insert_impl( const key_type& key, mapped_type x ) // strong
         {
             this->enforce_null_policy( x, "Null pointer in ptr_map_adapter::insert()" );
- auto_type ptr( x ); // nothrow
 
+ auto_type ptr( x, *this ); // nothrow
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
                  res = this->base().insert( std::make_pair( key, x ) ); // strong, commit
             if( res.second ) // nothrow
@@ -535,7 +533,8 @@
         {
             this->enforce_null_policy( x,
                   "Null pointer in 'ptr_map_adapter::insert()'" );
- auto_type ptr( x ); // nothrow
+
+ auto_type ptr( x, *this ); // nothrow
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                 res = this->base().insert( before.base(), std::make_pair( key, x ) );
                                         // strong, commit
@@ -562,7 +561,7 @@
             this->enforce_null_policy( p.second,
                   "Null pointer in 'ptr_map_adapter::insert()'" );
  
- auto_type ptr( this->null_policy_allocate_clone( p.second ) );
+ auto_type ptr( this->null_policy_allocate_clone(p.second), *this );
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                 result = this->base().insert( before.base(),
                                      std::make_pair(p.first,ptr.get()) ); // strong
@@ -668,7 +667,7 @@
             while( first != last )
             {
                 const_reference pair = *first.base(); // nothrow
- auto_type ptr( this->null_policy_allocate_clone( pair.second ) );
+ auto_type ptr( this->null_policy_allocate_clone(pair.second), *this );
                                                           // strong
                 safe_insert( pair.first,
                              boost::ptr_container::move( ptr ) );
@@ -760,7 +759,8 @@
         {
             this->enforce_null_policy( x,
                   "Null pointer in 'ptr_multimap_adapter::insert()'" );
- auto_type ptr( x ); // nothrow
+
+ auto_type ptr( x, *this ); // nothrow
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                 res = this->base().insert( std::make_pair( key, x ) );
                                         // strong, commit
@@ -772,7 +772,8 @@
         {
             this->enforce_null_policy( x,
                   "Null pointer in 'ptr_multimap_adapter::insert()'" );
- auto_type ptr( x ); // nothrow
+
+ auto_type ptr( x, *this ); // nothrow
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                 res = this->base().insert( before.base(),
                                            std::make_pair( key, x ) );

Modified: trunk/boost/ptr_container/ptr_sequence_adapter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_sequence_adapter.hpp (original)
+++ trunk/boost/ptr_container/ptr_sequence_adapter.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -244,8 +244,7 @@
         void push_back( value_type x ) // strong
         {
             this->enforce_null_policy( x, "Null pointer in 'push_back()'" );
-
- auto_type ptr( x ); // notrow
+ auto_type ptr( x, *this ); // notrow
             this->base().push_back( x ); // strong, commit
             ptr.release(); // nothrow
         }
@@ -259,8 +258,7 @@
         void push_front( value_type x )
         {
             this->enforce_null_policy( x, "Null pointer in 'push_front()'" );
-
- auto_type ptr( x ); // nothrow
+ auto_type ptr( x, *this ); // nothrow
             this->base().push_front( x ); // strong, commit
             ptr.release(); // nothrow
         }
@@ -275,7 +273,7 @@
         {
             BOOST_ASSERT( !this->empty() &&
                           "'pop_back()' on empty container" );
- auto_type ptr( static_cast<value_type>( this->base().back() ) );
+ auto_type ptr( static_cast<value_type>(this->base().back()), *this );
                                                        // nothrow
             this->base().pop_back(); // nothrow
             return ptr_container_detail::move( ptr ); // nothrow
@@ -285,7 +283,7 @@
         {
             BOOST_ASSERT( !this->empty() &&
                           "'pop_front()' on empty container" );
- auto_type ptr( static_cast<value_type>( this->base().front() ) );
+ auto_type ptr( static_cast<value_type>(this->base().front()), *this );
                                          // nothrow
             this->base().pop_front(); // nothrow
             return ptr_container_detail::move( ptr );
@@ -396,7 +394,7 @@
         {
             if( first == last )
                 return;
- scoped_deleter sd( first, last ); // strong
+ scoped_deleter sd( *this, first, last ); // strong
             this->insert_clones_and_release( sd, before ); // strong, commit
         }
 
@@ -482,7 +480,7 @@
             if( delete_from )
             {
                 BOOST_DEDUCED_TYPENAME base_type::scoped_deleter
- deleter( from, size ); // nothrow
+ deleter( *this, from, size ); // nothrow
                 this->base().insert( before.base(), from, from + size ); // strong
                 deleter.release(); // nothrow
             }

Modified: trunk/boost/ptr_container/ptr_set_adapter.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_set_adapter.hpp (original)
+++ trunk/boost/ptr_container/ptr_set_adapter.hpp 2009-06-26 19:34:48 EDT (Fri, 26 Jun 2009)
@@ -323,7 +323,7 @@
             while( first != last )
             {
                 if( this->find( *first ) == this->end() )
- insert( CloneAllocator::allocate_clone( *first ) ); // strong, commit
+ insert( this->null_policy_allocate_clone_from_iterator( first ) ); // strong, commit
                 ++first;
             }
         }
@@ -407,7 +407,7 @@
         {
             this->enforce_null_policy( x, "Null pointer in 'ptr_set::insert()'" );
             
- auto_type ptr( x );
+ auto_type ptr( x, *this );
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
                  res = this->base().insert( x );
             if( res.second )
@@ -426,7 +426,7 @@
         {
             this->enforce_null_policy( x, "Null pointer in 'ptr_set::insert()'" );
 
- auto_type ptr( x );
+ auto_type ptr( x, *this );
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                 res = this->base().insert( where.base(), x );
             if( *res == x )
@@ -530,7 +530,7 @@
         {
             while( first != last )
             {
- insert( CloneAllocator::allocate_clone( *first ) ); // strong, commit
+ insert( this->null_policy_allocate_clone_from_iterator( first ) ); // strong, commit
                 ++first;
             }
         }
@@ -618,7 +618,7 @@
         {
             this->enforce_null_policy( x, "Null pointer in 'ptr_multiset::insert()'" );
     
- auto_type ptr( x );
+ auto_type ptr( x, *this );
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
                  res = this->base().insert( x );
             ptr.release();


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