一、std::function介绍
std::function可调用函数对象模版类是一个函数包装器模版,该函数包装器模版能包装任何类型的可调用元素,如普通函数、函数指针、函数对象、普通函数模版、普通、成员函数、静态成员函数、静态成员函数模版等。包装器对象可以拷贝,包装器类型仅仅依赖于其调用特征,而不依赖于可调用元素自身的类型。
二、std::function定义
template< class R, class... Args >
class function;
参数说明:
R:调用函数返回值的类型
Args:函数参数类型
三、使用详解
1、可调用元素



2、将std::function绑定到可调用元素
1)绑定到普通函数

2)绑定到函数模版

3)绑定到lambda表达式

4)绑定到函数对象

5)绑定到类模版函数对象

6)绑定到静态成员函数

7)绑定到静态成员模版函数

8)绑定到成员函数(this指针,不预绑定)

9)绑定到成员模版函数(this指针,不预绑定)

四、详细代码参考
链接:https://pan.baidu.com/s/1qZbbKNM 密码:anm9
参考:
网友评论