|
1 | 1 | #include <functional>
|
2 | 2 |
|
3 |
| -int foo(int x, int y) { |
4 |
| - return x + y - 1; |
5 |
| -} |
| 3 | +int foo(int x, int y) { return x + y - 1; } |
6 | 4 |
|
7 | 5 | struct Bar {
|
8 |
| - int operator()() { |
9 |
| - return 66 ; |
10 |
| - } |
11 |
| - int add_num(int i) const { return i + 3 ; } |
12 |
| - int add_num2(int i) { |
13 |
| - std::function<int (int)> add_num2_f = [](int x) { |
14 |
| - return x+1; |
15 |
| - }; |
16 |
| - |
17 |
| - return add_num2_f(i); // Set break point at this line. |
18 |
| - } |
19 |
| -} ; |
| 6 | + int operator()() { return 66; } |
| 7 | + int add_num(int i) const { return i + 3; } |
| 8 | + int add_num2(int i) { |
| 9 | + std::function<int(int)> add_num2_f = [](int x) { return x + 1; }; |
| 10 | + |
| 11 | + return add_num2_f(i); // Set break point at this line. |
| 12 | + } |
| 13 | +}; |
20 | 14 |
|
21 | 15 | int foo2() {
|
22 |
| - auto f = [](int x) { |
23 |
| - return x+1; |
24 |
| - }; |
| 16 | + auto f = [](int x) { return x + 1; }; |
25 | 17 |
|
26 |
| - std::function<int (int)> foo2_f = f; |
| 18 | + std::function<int(int)> foo2_f = f; |
27 | 19 |
|
28 |
| - return foo2_f(10); // Set break point at this line. |
| 20 | + return foo2_f(10); // Set break point at this line. |
29 | 21 | }
|
30 | 22 |
|
31 |
| -int main (int argc, char *argv[]) |
32 |
| -{ |
| 23 | +int main(int argc, char *argv[]) { |
33 | 24 | int acc = 42;
|
34 |
| - std::function<int (int,int)> f1 = foo; |
35 |
| - std::function<int (int)> f2 = [acc,f1] (int x) -> int { |
36 |
| - return x+f1(acc,x); |
| 25 | + std::function<int(int, int)> f1 = foo; |
| 26 | + std::function<int(int)> f2 = [acc, f1](int x) -> int { |
| 27 | + return x + f1(acc, x); |
37 | 28 | };
|
38 | 29 |
|
39 | 30 | auto f = [](int x, int y) { return x + y; };
|
40 |
| - auto g = [](int x, int y) { return x * y; } ; |
41 |
| - std::function<int (int,int)> f3 = argc %2 ? f : g ; |
| 31 | + auto g = [](int x, int y) { return x * y; }; |
| 32 | + std::function<int(int, int)> f3 = argc % 2 ? f : g; |
42 | 33 |
|
43 |
| - Bar bar1 ; |
44 |
| - std::function<int ()> f4( bar1 ) ; |
45 |
| - std::function<int (const Bar&, int)> f5 = &Bar::add_num; |
| 34 | + Bar bar1; |
| 35 | + std::function<int()> f4(bar1); |
| 36 | + std::function<int(const Bar &, int)> f5 = &Bar::add_num; |
46 | 37 |
|
47 | 38 | int foo2_result = foo2();
|
48 | 39 | int bar_add_num2_result = bar1.add_num2(10);
|
49 | 40 |
|
50 |
| - return f1(acc,acc) + f2(acc) + f3(acc+1,acc+2) + f4() + f5(bar1, 10); // Set break point at this line. |
| 41 | + return f1(acc, acc) + f2(acc) + f3(acc + 1, acc + 2) + f4() + |
| 42 | + f5(bar1, 10); // Set break point at this line. |
51 | 43 | }
|
0 commit comments