Boost logo

Boost-Commit :

From: nesotto_at_[hidden]
Date: 2007-12-13 07:06:22


Author: nesotto
Date: 2007-12-13 07:06:21 EST (Thu, 13 Dec 2007)
New Revision: 42006
URL: http://svn.boost.org/trac/boost/changeset/42006

Log:
M. Marcin's improved version of erase_if + minor indentation tweaks
Text files modified:
   trunk/boost/ptr_container/ptr_sequence_adapter.hpp | 43 +++++++++++++++++++++++++++------------
   trunk/boost/ptr_container/ptr_set_adapter.hpp | 4 +-
   2 files changed, 32 insertions(+), 15 deletions(-)

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-12-13 07:06:21 EST (Thu, 13 Dec 2007)
@@ -143,6 +143,8 @@
         typedef BOOST_DEDUCED_TYPENAME base_type::value_type value_type;
         typedef BOOST_DEDUCED_TYPENAME base_type::reference reference;
         typedef BOOST_DEDUCED_TYPENAME base_type::auto_type auto_type;
+ typedef BOOST_DEDUCED_TYPENAME base_type::clone_allocator_type
+ clone_allocator_type;
          
         BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( ptr_sequence_adapter,
                                                  base_type )
@@ -537,6 +539,31 @@
             }
         };
 
+ template< class Fun, class Arg1 >
+ class void_ptr_delete_if
+ {
+ Fun fun;
+ public:
+
+ void_ptr_delete_if() : fun(Fun())
+ { }
+
+ void_ptr_delete_if( Fun f ) : fun(f)
+ { }
+
+ bool operator()( void* r ) const
+ {
+ BOOST_ASSERT( r != 0 );
+ Arg1 arg1 = static_cast<Arg1>(r);
+ if( fun( *arg1 ) )
+ {
+ clone_allocator_type::deallocate_clone( arg1 );
+ return true;
+ }
+ return false;
+ }
+ };
+
         void compact_and_erase_nulls( iterator first, iterator last ) // nothrow
         {
             
@@ -605,19 +632,9 @@
         void erase_if( iterator first, iterator last, Pred pred )
         {
             range_check(first,last);
-
- iterator next = first;
- for( ; next != last; ++next )
- {
- BOOST_ASSERT( !::boost::is_null(next) );
- if( pred( *next ) )
- {
- this->remove( next ); // delete object
- *next.base() = 0; // mark pointer as deleted
- }
- }
-
- compact_and_erase_nulls( first, last );
+ this->base().erase( std::remove_if( first.base(), last.base(),
+ void_ptr_delete_if<Pred,value_type>(pred) ),
+ this->base().end() );
         }
         
         template< class Pred >

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-12-13 07:06:21 EST (Thu, 13 Dec 2007)
@@ -246,9 +246,9 @@
         typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
                      auto_type;
         typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::key_compare
- key_compare;
+ key_compare;
         typedef BOOST_DEDUCED_TYPENAME VoidPtrSet::allocator_type
- allocator_type;
+ allocator_type;
     private:
         
         template< typename II >


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