//std::bind 绑定
//std::placeholders 占位符
//std::function 函数
//这三个一般都是同时出现的
//例:
void onParseCallback(std::shared_ptr<void> param)
{
//回调函数
}
//使用fun替代onParseCallback
auto fun = std::bind(&onParseCallback, placeholders::_1);
//使用宏替代onParseCallback,BIND_CALLBACK_3(onParseCallback)
#define BIND_CALLBACK_1(func) std::bind(&func, this, placeholders::_1) //成员函数要加个this
#define BIND_CALLBACK_2(func) std::bind(&func, this, placeholders::_1, placeholders::_2) //两个占位符,代表两个形参
#define BIND_CALLBACK_3(func) std::bind(&func, placeholders::_1) //普通函数
//使用OperationDelegate代表void(std::shared_ptr<void>)类型的函数
typedef std::function<void(std::shared_ptr<void>)> OperationDelegate;
//例子:定义函数形参为OperationDelegate类型,使用时传入fun
class EqsParser
{
public:
EqsParser(OperationDelegate callback);
~EqsParser();
}
EqsParser eqs_parser(onParseCallback);
或者
auto fun = std::bind(onParseCallback, placeholders::_1);
EqsParser eqs_parser(fun);
或者
EqsParser eqs_parser(BIND_CALLBACK_3(onParseCallback));