User:MikeMol/playground: Difference between revisions

From Rosetta Code
m (playing around...)
 
m (MikeMol moved page User:Short Circuit/playground to User:MikeMol/playground: Miraheze migration)
 
(No difference)

Latest revision as of 18:27, 24 August 2022

<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>