Skip to content

Commit d7a1c40

Browse files
lambda_function.cpp
1 parent 20b2c36 commit d7a1c40

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lambda_function.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm> //for_each
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
std::vector<int> some_list;
10+
int total = 0;
11+
for (int i=0;i<5;i++) some_list.push_back(i);
12+
13+
//C++ 11 lambda function: [capture](parameters)->return-type{body}
14+
std::for_each(begin(some_list), end(some_list), [&total](int x) {
15+
total += x;
16+
});
17+
cout << total << endl;
18+
return 0;
19+
}

0 commit comments

Comments
 (0)