Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
lambda-functor.cpp
Go to the documentation of this file.
1 #include <functional>
2 #include <iostream>
3 using std::cout;
4 using std::endl;
5 
6 std::function<int(int)> makeCountingAdder(int& counter)
7 {
8  return [&counter](int x) -> int {
9  int val = counter + x;
10  counter++;
11  return val;
12  };
13 }
14 
15 int main()
16 {
17  int counter = 40;
18  auto adder = makeCountingAdder(counter);
19  cout << adder(2) << endl;
20  cout << adder(4) << endl;
21  cout << adder(8) << endl;
22  cout << "Current counter count: " << counter << endl;
23 }
int main()
std::function< int(int)> makeCountingAdder(int &counter)