1.5.3.3 Applying



ufunc for_each(i,i,ufunc)

Apply a function to every item in a range and return the function.

ufunc may not return value.




void fun(int n){ 
    cout<<""<<n; 
} ____________________________________________________________________________________//all function definition end no semicolon 
 
struct Sum{ 
    Sum(): sumEven{0} { }  _____________________________________________//no semicolon here 
    void operator()(int n) { if(n%2 ==0) ; sumEven += n; } 
    int sumEven; 
}; ____________________________________________________________// type definition need semicolon 
 
vector<int> nums{3, 4, 2, 8, 15, 267}; 
for_each(nums.begin(), nums.end(), fun); ________________________// no () here 
Sum s = for_each(nums.begin(), nums.end(), Sum()); ________________________//have() here 
for_each(nums.begin(), nums.end(), [sumEven](int n){ 
                                               if(n%2==0) sumEven+=n; 
                                               });

Transforming




o transform(i1,i1end,o,ufunc)
o transform(i1,i1end,i2, o, bfunc)

Transform one range of values into another.

Ret of ufunc or bfunc writed to o.