两个实际应用到lambda表达式的代码。
std::vector<int> v ={1,2,3,4,5,6};
int even_count =0;
for_each(v.begin(), v.end(),[&even_count](int val){
if(!(val &1)){
++ even_count;
}
});
std::cout <<"The number of even is "<< even_count << std::endl;
int count = std::count_if( coll.begin(), coll.end(),[](int x){return x >10;});
int count = std::count_if( coll.begin(), coll.end(),[](int x){return x <10;});
int count = std::count_if( coll.begin(), coll.end(),[](int x){return x >5&& x<10;});