123456789101112131415161718192021222324
void hello(int count){ cout << "hello number:" << count << endl;}class CHello{public: void hello(int count) { cout << "CHello::hello number:" << count << endl; }};int main(){ auto f_hello9 = bind(&hello, 9); f_hello9(); // 这样就不用传参数了 CHello c; auto f_hello10 = bind(&CHello::hello, &c, 10); // 成员函数需要传this f_hello10(); auto f_hello11 = bind(&CHello::hello, &c, placeholders::_1); // 占位符 f_hello11(11);}
12345678910
void func(int& n){ cout << "lvalue=" << n << endl;}void func(int&& n){ cout << "rvalue=" << n << endl;}template<typename T>void revoke(T &&t){ func(forward<T>(t));}