added lambda example

This commit is contained in:
Stephen M. McQuay 2012-05-05 09:25:28 -06:00
parent ea645e96d9
commit 52dabdd8c0
1 changed files with 17 additions and 0 deletions

17
lambda.cc Normal file
View File

@ -0,0 +1,17 @@
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
vector<int> ints = {1, 2, 3, 4, 5, 6};
int total = 0;
for_each(begin(ints), end(ints), [&total](int x) {
total += x;
});
cout << "total: " << total << endl;
auto my_lambda_doubling_func = [&](int x) -> int { return x * 2; };
cout << my_lambda_doubling_func(total) << endl;
return 0;
}