std::function

文档

用法

类似C语言中的函数指针
目前使用过的用法

  1. vector中存放lambda表达式指明元素类型
auto op1 = [](int a, int b) -> int {return a + b;};
auto op2 = [](int a, int b) -> int {return a - b;};
auto op3 = [](int a, int b) -> int {return a ^ b;};
vector<function<int(int, int)>> ops = {op1, op2, op3};

一道例题,不使用lambdavector相结合,就需要写三段重复度很高的代码

原文地址:https://www.cnblogs.com/G-H-Y/p/15499442.html