| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | |
| 27 | auto f = [](int value) { |
| 28 | std::cout << value << std::endl; |
| 29 | }; |
| 30 | functional(f); // 函数指针调用 |
| 31 | f(1); // lambda 表达式调用 |
| 32 | |
| 33 | // std::function 包装了一个返回值为 int, 参数为 int 的函数 |
| 34 | std::function<int(int)> func = foo2; |
| 35 | |
| 36 | int important = 10; |
| 37 | std::function<int(int)> func2 = [&](int value) -> int { |
| 38 | return 1+value+important; |
| 39 | }; |
| 40 | std::cout << func(10) << std::endl; |
| 41 | std::cout << func2(10) << std::endl; |
| 42 | |
| 43 | |
| 44 | // 将参数1,2绑定到函数 foo 上,但是使用 std::placeholders::_1 来对第一个参数进行占位 |
| 45 | auto bindFoo = std::bind(foo3, std::placeholders::_1, 1,2); |
| 46 | // 这时调用 bindFoo 时,只需要提供第一个参数即可 |
| 47 | bindFoo(1); |
| 48 | |
| 49 | |
| 50 | return 0; |
| 51 | } |
nothing calls this directly
no test coverage detected