cpp11/lambda.cc

25 lines
664 B
C++
Raw Permalink Normal View History

2012-05-05 08:25:28 -07:00
#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;
2012-05-25 07:17:47 -07:00
vector<int> orderme = {46, 78, 2, 75, 33, 1, 65, 48, 45, 73};
sort(orderme.begin(), orderme.end(), [](int x, int y) -> bool {
return x < y;
});
for(auto x: orderme) {
cout << x << endl;
}
2012-05-05 08:25:28 -07:00
return 0;
}