- Basic Test Code
-
#include<iostream>
#include<functional>
void func(void)
{
std::cout << __FUNCTION__ << std::endl;
}
void callback(std::function<int(int,char*)> fr)
{
fr(1,"gdg");
}
int strlength(int n,constchar* str)
{
return n + strlen(str);
}
void outPut(int x,int y)
{
std::cout << x <<" "<< y << std::endl;
}
int main()
{
//测试bind
auto fr = std::bind(strlength, std::placeholders::_1, std::placeholders::_2);
//function作为函数参数
callback(fr);
std::bind(strlength,1,"hhha")();
STD : bind ( Strlength std :: placeholders : _1 "HHA" 45 //the first parameter is passed out from the outside, the second parameter is already set
STD : bind ( Strlength 23 STD : placeholders : _1 "Lallaa" //bind in the order of the parameters of the function
STD : bind ( Strlength std :: placeholders : _2 STD : placeholders : _1 "HHAFDSF" 25 //the first argument with the passed-in second parameter, the second argument with the first parameter passed in
std::bind(strlength, std::placeholders::_1, std::placeholders::_3)(12,45,"fhsafdf");//对,第二个参数没用到
}
From for notes (Wiz)
The Std::bind and function of c++11