I l@ve RuBoard Previous Section Next Section

remove_if(), remove_copy_if()

remove_if() removes all elements within the sequence for which the predicate operation evaluates as true. Otherwise, remove_if() and remove_copy_if() behave the same as remove() and remove_copy() ?see the earlier discussion.



#include <algorithm> 





class EvenValue { 


public: 


   bool operator()( int value ) { 


        return value % 2 ? false : true; } 


}; 





int ia[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 }; 


vector<int> vec( ia, ia+10 ); 





iter = remove_if( vec.begin(), vec.end(), bind2nd(less<int>(),10) ); 


vec.erase( iter, vec.end() ); // sequence now: 13 21 34 





int ia2[10]; // ia2: 1 1 3 5 13 21 


remove_copy_if( ia, ia+10,ia2, EvenValue() ); 
    I l@ve RuBoard Previous Section Next Section