I l@ve RuBoard Previous Section Next Section

for_each()

for_each() takes a third parameter that represents an operation that is applied to each element in turn. The operation cannot modify the elements (we can use transform() for that). Although the operation may return a value, that value is ignored.



#include <algorithm> 


template <typename Type> 


    void print_elements( Type elem ) { cout << elem << " "; } 





for_each( ivec.begin(), ivec.end(), print_elements ); 
    I l@ve RuBoard Previous Section Next Section