I will start posting cool little blocks of code, like short poems when I see neat little things to do ..
Find multiples in a vector the C++11 way
1234567891011121314
#include <iostream>#include <vector>usingnamespacestd;intmain(){vector<int>v{12,324,45,65,787,9};//Uniform initializationcout<<"In vector: ";for(autoval:v){cout<<val<<", ";}//Range based forintm=5;cout<<"there are "<<count_if(v.begin(),v.end(),[m](inti){returni%m==0;})//lambdas<<" multiples of "<<m<<endl;}
In vector: 12, 324, 45, 65, 787, 9, there are 2 multiples of 5
For some more depth on the functional goodness see this Dr. Dobbs article