Boost logo

Boost-Commit :

From: nesotto_at_[hidden]
Date: 2007-10-22 18:50:53


Author: nesotto
Date: 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
New Revision: 40306
URL: http://svn.boost.org/trac/boost/changeset/40306

Log:
minor refactorings to support copyability etc

Text files modified:
   trunk/boost/ptr_container/detail/associative_ptr_container.hpp | 49 ++++++++++++++++++++++++--------------
   trunk/boost/ptr_container/detail/reversible_ptr_container.hpp | 51 ++++++++++++++++++++++++++++-----------
   trunk/boost/ptr_container/ptr_array.hpp | 10 +++---
   trunk/boost/ptr_container/ptr_list.hpp | 5 +--
   trunk/boost/ptr_container/ptr_map_adapter.hpp | 30 +++++++++++-----------
   trunk/boost/ptr_container/ptr_sequence_adapter.hpp | 40 +++++++++++++++---------------
   trunk/boost/ptr_container/ptr_set_adapter.hpp | 24 +++++++++---------
   trunk/boost/ptr_container/ptr_vector.hpp | 2
   8 files changed, 122 insertions(+), 89 deletions(-)

Modified: trunk/boost/ptr_container/detail/associative_ptr_container.hpp
==============================================================================
--- trunk/boost/ptr_container/detail/associative_ptr_container.hpp (original)
+++ trunk/boost/ptr_container/detail/associative_ptr_container.hpp 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -56,14 +56,14 @@
 
        template< class Compare, class Allocator >
        associative_ptr_container( const Compare& comp,
- const Allocator& a )
+ const Allocator& a )
          : base_type( comp, a )
        { }
 
        template< class InputIterator, class Compare, class Allocator >
        associative_ptr_container( InputIterator first, InputIterator last,
- const Compare& comp,
- const Allocator& a )
+ const Compare& comp,
+ const Allocator& a )
          : base_type( first, last, comp, a )
        { }
 
@@ -72,21 +72,34 @@
          : base_type( r, key_compare() )
        { }
 
+ associative_ptr_container( const associative_ptr_container& r )
+ : base_type( r.begin(), r.end(), key_compare(),
+ BOOST_DEDUCED_TYPENAME Config::allocator_type() )
+ { }
+
        template< class PtrContainer >
- void operator=( std::auto_ptr<PtrContainer> r )
+ associative_ptr_container& operator=( std::auto_ptr<PtrContainer> r ) // nothrow
        {
            base_type::operator=( r );
+ return *this;
+ }
+
+ associative_ptr_container& operator=( const associative_ptr_container& r ) // strong
+ {
+ associative_ptr_container clone( r );
+ this->swap( clone );
+ return *this;
        }
 
     public: // associative container interface
         key_compare key_comp() const
         {
- return this->c_private().key_comp();
+ return this->base().key_comp();
         }
 
         value_compare value_comp() const
         {
- return this->c_private().value_comp();
+ return this->base().value_comp();
         }
 
         iterator erase( iterator before ) // nothrow
@@ -97,17 +110,17 @@
             this->remove( before ); // nothrow
             iterator res( before ); // nothrow
             ++res; // nothrow
- this->c_private().erase( before.base() ); // nothrow
+ this->base().erase( before.base() ); // nothrow
             return res; // nothrow
         }
 
         size_type erase( const key_type& x ) // nothrow
         {
- iterator i( this->c_private().find( x ) ); // nothrow
+ iterator i( this->base().find( x ) ); // nothrow
             if( i == this->end() ) // nothrow
                 return 0u; // nothrow
             this->remove( i ); // nothrow
- return this->c_private().erase( x ); // nothrow
+ return this->base().erase( x ); // nothrow
         }
 
         iterator erase( iterator first,
@@ -118,7 +131,7 @@
                 ++res; // nothrow
 
             this->remove( first, last ); // nothrow
- this->c_private().erase( first.base(), last.base() );// nothrow
+ this->base().erase( first.base(), last.base() );// nothrow
             return res; // nothrow
         }
 
@@ -131,8 +144,8 @@
             BOOST_ASSERT( (void*)&from != (void*)this );
             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
 
- this->c_private().insert( *object.base() ); // strong
- from.c_private().erase( object.base() ); // nothrow
+ this->base().insert( *object.base() ); // strong
+ from.base().erase( object.base() ); // nothrow
         }
 
         template< class AssociatePtrCont >
@@ -147,11 +160,11 @@
             for( ; first != last; )
             {
                 BOOST_ASSERT( first != from.end() );
- this->c_private().insert( *first.base() ); // strong
+ this->base().insert( *first.base() ); // strong
                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator
                     to_delete( first );
                 ++first;
- from.c_private().erase( to_delete.base() ); // nothrow
+ from.base().erase( to_delete.base() ); // nothrow
                 ++res;
             }
 
@@ -166,9 +179,9 @@
             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
 
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
- this->c_private().insert( *object.base() ); // strong
+ this->base().insert( *object.base() ); // strong
             if( p.second )
- from.c_private().erase( object.base() ); // nothrow
+ from.base().erase( object.base() ); // nothrow
 
             return p.second;
         }
@@ -186,13 +199,13 @@
             {
                 BOOST_ASSERT( first != from.end() );
                 std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
- this->c_private().insert( *first.base() ); // strong
+ this->base().insert( *first.base() ); // strong
                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator
                     to_delete( first );
                 ++first;
                 if( p.second )
                 {
- from.c_private().erase( to_delete.base() ); // nothrow
+ from.base().erase( to_delete.base() ); // nothrow
                     ++res;
                 }
             }

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 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -139,14 +139,8 @@
         Cont c_;
 
     public:
- Cont& c_private() { return c_; }
- const Cont& c_private() const { return c_; }
-
- protected: // todo: use base() instead of c_private().
- Cont& base() { return c_; }
-
- public:
- const Cont& base() const { return c_; }
+ Cont& base() { return c_; }
+ const Cont& base() const { return c_; }
         
     public: // typedefs
         typedef Ty_* value_type;
@@ -200,12 +194,6 @@
             sd.release();
         }
         
- void insert_clones_and_release( scoped_deleter& sd ) // strong
- {
- c_.insert( sd.begin(), sd.end() );
- sd.release();
- }
-
         template< class ForwardIterator >
         void clone_assign( ForwardIterator first,
                            ForwardIterator last ) // strong
@@ -243,10 +231,20 @@
             sd.release();
         }
 
+ void insert_clones_and_release( scoped_deleter& sd ) // strong
+ {
+ c_.insert( sd.begin(), sd.end() );
+ sd.release();
+ }
+
         template< class I >
         void remove( I i )
         {
             null_policy_deallocate_clone( Config::get_const_pointer(i) );
+//#ifndef NDEBUG
+// *i = 0xbadbad;
+//#endif
+
         }
 
         template< class I >
@@ -354,6 +352,20 @@
                                   const allocator_type& a )
         : c_( comp, a ) {}
 
+ template< class InputIterator, class Compare >
+ reversible_ptr_container( InputIterator first,
+ InputIterator last,
+ const Compare& comp,
+ const allocator_type& a )
+ : c_( comp, a )
+ {
+ if( first == last )
+ return;
+
+ scoped_deleter sd( first, last );
+ insert_clones_and_release( sd );
+ }
+
         template< class PtrContainer, class Compare >
         reversible_ptr_container( std::auto_ptr<PtrContainer> clone,
                                   Compare comp )
@@ -639,9 +651,10 @@
     PC( std::auto_ptr<this_type> r ) \
     : base_type ( r ) { } \
                                                     \
- void operator=( std::auto_ptr<this_type> r ) \
+ PC& operator=( std::auto_ptr<this_type> r ) \
     { \
         base_type::operator=( r ); \
+ return *this; \
     } \
                                                     \
     std::auto_ptr<this_type> release() \
@@ -675,6 +688,14 @@
     
     } // namespace 'ptr_container_detail'
 
+ //
+ // @remark: expose movability of internal move-pointer
+ //
+ namespace ptr_container
+ {
+ using ptr_container_detail::move;
+ }
+
 } // namespace 'boost'
 
 #endif

Modified: trunk/boost/ptr_container/ptr_array.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_array.hpp (original)
+++ trunk/boost/ptr_container/ptr_array.hpp 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -131,8 +131,8 @@
 
             this->enforce_null_policy( r, "Null pointer in 'ptr_array::replace()'" );
 
- auto_type res( static_cast<U*>( this->c_private()[idx] ) ); // nothrow
- this->c_private()[idx] = r; // nothrow
+ auto_type res( static_cast<U*>( this->base()[idx] ) ); // nothrow
+ this->base()[idx] = r; // nothrow
             return move(res); // nothrow
         }
 
@@ -151,8 +151,8 @@
             BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= N, bad_index,
                                                  "'replace()' aout of bounds" );
 
- auto_type res( static_cast<U*>( this->c_private()[idx] ) ); // nothrow
- this->c_private()[idx] = ptr.release(); // nothrow
+ auto_type res( static_cast<U*>( this->base()[idx] ) ); // nothrow
+ this->base()[idx] = ptr.release(); // nothrow
             return move(res); // nothrow
         }
 
@@ -187,7 +187,7 @@
         bool is_null() const
         {
             BOOST_STATIC_ASSERT( idx < N );
- return this->c_private()[idx] == 0;
+ return this->base()[idx] == 0;
         }
         
     public: // serialization

Modified: trunk/boost/ptr_container/ptr_list.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_list.hpp (original)
+++ trunk/boost/ptr_container/ptr_list.hpp 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -56,8 +56,7 @@
         template< typename Compare >
         void merge( ptr_list& x, Compare comp )
         {
- this->c_private().merge( x.c_private(), void_ptr_indirect_fun<Compare,T>( comp ) );
- }
+ this->base().merge( x.base(), void_ptr_indirect_fun<Compare,T>( comp ) ); }
 
         void sort()
         {
@@ -67,7 +66,7 @@
         template< typename Compare >
         void sort( Compare comp )
         {
- this->c_private().sort( void_ptr_indirect_fun<Compare,T>( comp ) );
+ this->base().sort( void_ptr_indirect_fun<Compare,T>( comp ) );
         }
 
     }; // class 'ptr_list'

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 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -157,14 +157,14 @@
 
         mapped_reference insert_lookup( const key_type& key )
         {
- void*& ref = this->c_private()[key];
+ void*& ref = this->base()[key];
             if( ref )
             {
                 return *static_cast<mapped_type>(ref);
             }
             else
             {
- eraser e(&this->c_private(),key); // nothrow
+ eraser e(&this->base(),key); // nothrow
                 mapped_type res = new T(); // strong
                 ref = res; // nothrow
                 e.release(); // nothrow
@@ -203,44 +203,44 @@
 
         iterator find( const key_type& x )
         {
- return iterator( this->c_private().find( x ) );
+ return iterator( this->base().find( x ) );
         }
 
         const_iterator find( const key_type& x ) const
         {
- return const_iterator( this->c_private().find( x ) );
+ return const_iterator( this->base().find( x ) );
         }
 
         size_type count( const key_type& x ) const
         {
- return this->c_private().count( x );
+ return this->base().count( x );
         }
                                                                                      
         iterator lower_bound( const key_type& x )
         {
- return iterator( this->c_private().lower_bound( x ) );
+ return iterator( this->base().lower_bound( x ) );
         }
                                                                                      
         const_iterator lower_bound( const key_type& x ) const
         {
- return const_iterator( this->c_private().lower_bound( x ) );
+ return const_iterator( this->base().lower_bound( x ) );
         }
                                                                                      
         iterator upper_bound( const key_type& x )
         {
- return iterator( this->c_private().upper_bound( x ) );
+ return iterator( this->base().upper_bound( x ) );
         }
                                                                                      
         const_iterator upper_bound( const key_type& x ) const
         {
- return const_iterator( this->c_private().upper_bound( x ) );
+ return const_iterator( this->base().upper_bound( x ) );
         }
                                                                                      
         iterator_range<iterator> equal_range( const key_type& x )
         {
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,
                       BOOST_DEDUCED_TYPENAME base_type::ptr_iterator>
- p = this->c_private().equal_range( x );
+ p = this->base().equal_range( x );
             return make_iterator_range( iterator( p.first ), iterator( p.second ) );
         }
                                                                                      
@@ -248,7 +248,7 @@
         {
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator,
                       BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator>
- p = this->c_private().equal_range( x );
+ p = this->base().equal_range( x );
             return make_iterator_range( const_iterator( p.first ),
                                         const_iterator( p.second ) );
         }
@@ -350,7 +350,7 @@
         {
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
                 res =
- this->c_private().insert( std::make_pair( key, ptr.get() ) ); // strong, commit
+ this->base().insert( std::make_pair( key, ptr.get() ) ); // strong, commit
             if( res.second ) // nothrow
                 ptr.release(); // nothrow
         }
@@ -418,7 +418,7 @@
             auto_type ptr( x ); // nothrow
 
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
- res = this->c_private().insert( std::make_pair( key, x ) ); // strong, commit
+ res = this->base().insert( std::make_pair( key, x ) ); // strong, commit
             if( res.second ) // nothrow
                 ptr.release(); // nothrow
             return std::make_pair( iterator( res.first ), res.second ); // nothrow
@@ -535,7 +535,7 @@
 
         void safe_insert( const key_type& key, auto_type ptr ) // strong
         {
- this->c_private().insert(
+ this->base().insert(
                            std::make_pair( key, ptr.get() ) ); // strong, commit
             ptr.release(); // nothrow
         }
@@ -600,7 +600,7 @@
 
             auto_type ptr( x ); // nothrow
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->c_private().insert( std::make_pair( key, x ) );
+ res = this->base().insert( std::make_pair( key, x ) );
                                         // strong, commit
             ptr.release(); // notrow
             return iterator( res );

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 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -174,7 +174,7 @@
             this->enforce_null_policy( x, "Null pointer in 'push_back()'" );
 
             auto_type ptr( x ); // notrow
- this->c_private().push_back( x ); // strong, commit
+ this->base().push_back( x ); // strong, commit
             ptr.release(); // nothrow
         }
 
@@ -189,7 +189,7 @@
             this->enforce_null_policy( x, "Null pointer in 'push_front()'" );
 
             auto_type ptr( x ); // nothrow
- this->c_private().push_front( x ); // strong, commit
+ this->base().push_front( x ); // strong, commit
             ptr.release(); // nothrow
         }
 
@@ -205,8 +205,8 @@
                                                  bad_ptr_container_operation,
                                           "'pop_back()' on empty container" );
             auto_type ptr( static_cast<value_type>(
- this->c_private().back() ) ); // nothrow
- this->c_private().pop_back(); // nothrow
+ this->base().back() ) ); // nothrow
+ this->base().pop_back(); // nothrow
             return ptr_container_detail::move( ptr ); // nothrow
         }
 
@@ -216,8 +216,8 @@
                                                  bad_ptr_container_operation,
                                          "'pop_front()' on empty container" );
             auto_type ptr( static_cast<value_type>(
- this->c_private().front() ) ); // nothrow
- this->c_private().pop_front(); // nothrow
+ this->base().front() ) ); // nothrow
+ this->base().pop_front(); // nothrow
             return ptr_container_detail::move( ptr );
         }
         
@@ -263,14 +263,14 @@
         {
             BOOST_ASSERT( n < this->size() );
             BOOST_ASSERT( !this->is_null( n ) );
- return *static_cast<value_type>( this->c_private()[n] );
+ return *static_cast<value_type>( this->base()[n] );
         }
         
         const_reference operator[]( size_type n ) const // nothrow
         {
             BOOST_ASSERT( n < this->size() );
             BOOST_ASSERT( !this->is_null( n ) );
- return *static_cast<value_type>( this->c_private()[n] );
+ return *static_cast<value_type>( this->base()[n] );
         }
         
         reference at( size_type n )
@@ -293,17 +293,17 @@
         
         size_type capacity() const
         {
- return this->c_private().capacity();
+ return this->base().capacity();
         }
         
         void reserve( size_type n )
         {
- this->c_private().reserve( n );
+ this->base().reserve( n );
         }
 
         void reverse()
         {
- this->c_private().reverse();
+ this->base().reverse();
         }
 
     public: // assign, insert, transfer
@@ -376,11 +376,11 @@
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
- this->c_private().
+ this->base().
                 insert( before.base(),
                         first.base(), last.base() ); // strong
- from.c_private().erase( first.base(),
- last.base() ); // nothrow
+ from.base().erase( first.base(),
+ last.base() ); // nothrow
         }
 
         template< class PtrSeqAdapter >
@@ -391,10 +391,10 @@
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
- this->c_private().
+ this->base().
                 insert( before.base(),
                         *object.base() ); // strong
- from.c_private().erase( object.base() ); // nothrow
+ from.base().erase( object.base() ); // nothrow
         }
 
 #ifdef BOOST_NO_SFINAE
@@ -415,10 +415,10 @@
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
- this->c_private().
+ this->base().
                 insert( before.base(),
                         from.begin().base(), from.end().base() ); // strong
- from.c_private().clear(); // nothrow
+ from.base().clear(); // nothrow
         }
 
     public: // null functions
@@ -426,7 +426,7 @@
         bool is_null( size_type idx ) const
         {
             BOOST_ASSERT( idx < this->size() );
- return this->c_private()[idx] == 0;
+ return this->base()[idx] == 0;
         }
 
     public: // algorithms
@@ -485,7 +485,7 @@
                                                     first.base(),
                                                     last.base(),
                                                     is_not_zero_ptr() );
- this->c_private().erase( p, this->end().base() );
+ this->base().erase( p, this->end().base() );
             
         }
 

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 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -129,42 +129,42 @@
                  
         iterator find( const key_type& x )
         {
- return iterator( this->c_private().
+ return iterator( this->base().
                              find( const_cast<key_type*>(&x) ) );
         }
 
         const_iterator find( const key_type& x ) const
         {
- return const_iterator( this->c_private().
+ return const_iterator( this->base().
                                    find( const_cast<key_type*>(&x) ) );
         }
 
         size_type count( const key_type& x ) const
         {
- return this->c_private().count( const_cast<key_type*>(&x) );
+ return this->base().count( const_cast<key_type*>(&x) );
         }
                                                                                      
         iterator lower_bound( const key_type& x )
         {
- return iterator( this->c_private().
+ return iterator( this->base().
                              lower_bound( const_cast<key_type*>(&x) ) );
         }
                                                                                      
         const_iterator lower_bound( const key_type& x ) const
         {
- return const_iterator( this->c_private().
+ return const_iterator( this->base().
                                    lower_bound( const_cast<key_type*>(&x) ) );
         }
                                                                                      
         iterator upper_bound( const key_type& x )
         {
- return iterator( this->c_private().
+ return iterator( this->base().
                              upper_bound( const_cast<key_type*>(&x) ) );
         }
                                                                                      
         const_iterator upper_bound( const key_type& x ) const
         {
- return const_iterator( this->c_private().
+ return const_iterator( this->base().
                                    upper_bound( const_cast<key_type*>(&x) ) );
         }
                                                                                      
@@ -172,7 +172,7 @@
         {
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,
                       BOOST_DEDUCED_TYPENAME base_type::ptr_iterator>
- p = this->c_private().
+ p = this->base().
                 equal_range( const_cast<key_type*>(&x) );
             return make_iterator_range( iterator( p.first ),
                                         iterator( p.second ) );
@@ -182,7 +182,7 @@
         {
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator,
                       BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator>
- p = this->c_private().
+ p = this->base().
                 equal_range( const_cast<key_type*>(&x) );
             return make_iterator_range( const_iterator( p.first ),
                                         const_iterator( p.second ) );
@@ -271,7 +271,7 @@
             
             auto_type ptr( x );
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
- res = this->c_private().insert( x );
+ res = this->base().insert( x );
             if( res.second )
                 ptr.release();
             return std::make_pair( iterator( res.first ), res.second );
@@ -290,7 +290,7 @@
 
             auto_type ptr( x );
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->c_private().insert( where.base(), x );
+ res = this->base().insert( where.base(), x );
             if( *res == x )
                 ptr.release();
             return iterator( res);
@@ -441,7 +441,7 @@
     
             auto_type ptr( x );
             BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->c_private().insert( x );
+ res = this->base().insert( x );
             ptr.release();
             return iterator( res );
         }

Modified: trunk/boost/ptr_container/ptr_vector.hpp
==============================================================================
--- trunk/boost/ptr_container/ptr_vector.hpp (original)
+++ trunk/boost/ptr_container/ptr_vector.hpp 2007-10-22 18:50:52 EDT (Mon, 22 Oct 2007)
@@ -51,7 +51,7 @@
           : base_class(alloc)
         {
             if( n > 0 )
- this->c_private().reserve( n );
+ this->base().reserve( n );
         }
 
     public: // serialization


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