I l@ve RuBoard Previous Section Next Section

replace_if(), replace_copy_if()

replace_if() replaces all elements within the sequence with new_value for which the predicate comparison operation evaluates as true.



#include <algorithm> 


int new_value = 0; 


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


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





// new sequence:  0 0 0 0 0 0 0 13 21 34 


replace_if( vec.begin(), vec.end(), 


            bind2nd(less<int>(),10), new_value ); 
    I l@ve RuBoard Previous Section Next Section