Mat*_*ank 17
首先,我质疑你的断言,你使用它太重了.
其次,如果需要控制行为,请滚动自己的模板.
第三,如果您害怕滚动自己的模板,我会质疑您判断的能力boost::bind
太大而无法使用.
我不熟悉 boost:bind,但它是这样的吗?
#include <iostream>
void foo (int const& x) {
std::cout << "x = " << x << std::endl;
}
void bar (std::string const& s) {
std::cout << "s = " << s << std::endl;
}
template<class T>
void relay (void (*f)(T const&), T const& a) {
f(a);
}
int main (int argc, char *argv[])
{
std::string msg("Hello World!");
relay (foo, 1138);
relay (bar, msg);
}
Run Code Online (Sandbox Code Playgroud)
输出 -
x = 1138
s = Hello World!
Run Code Online (Sandbox Code Playgroud)