标签:style blog io os ar for sp div 2014
->后加上的是Lambda表达式返回值的类型,如(3)中返回了一个int类型的变量
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void func(int &x)
{
cout << x;
}
int main()
{
vector<int> iv{0, 1, 2, 3};
for_each(iv.begin(), iv.end(), func);
cout << endl;
for_each(iv.begin(), iv.end(), [=](int &x){ cout << x; }); //(1)
cout << endl;
int param = 1;
for_each(iv.begin(), iv.end(), [param](int &x){ cout << x + param; }); //(2)
cout << endl;
for_each(iv.begin(), iv.end(), [=](int&x)->int{ return x; }); //(3)
return 0;
}标签:style blog io os ar for sp div 2014
原文地址:http://www.cnblogs.com/lcchuguo/p/4005914.html