User:MikeMol/playground

From Rosetta Code

<cpp>class CSquare : unary_function<double, void> {

 double operator(double x) {return x*x;}

}

void func() {

 vector<double> src(100), squared(100);
 iota(src.begin(), src.end(), 1);
 transform(src.begin(), src.end(), squared.begin(), CSquare());

} </cpp>

<cpp>void func() {

 vector<double> src(100), squared(100);
 iota(src.begin(), src.end(), 1);
 transform(src.begin(), src.end(), squared.begin(), [](double x){return x*x;});

} </cpp>