测试用例bind
// For more information, see http://www.boost.org/
#include <boost/function.hpp>
#include <iostream>
#include <functional>
struct X {
int foo(int);
};
int X::foo(int x) { return -x; }
int main()
{
boost::function1<int, int> f;
X x;
f = std::bind1st(
std::mem_fun(&X::foo), &x);
f(5); // Call x.foo(5)
return 0;
}
测试用例(ref)
#include <boost/function.hpp>
#include <iostream>
struct stateful_type { int operator()(int) const { return 0; } };
int main()
{
stateful_type a_function_object;
boost::function1<int, int> f;
f = boost::ref(a_function_object);
boost::function1<int, int> f2(f);
return 0;
}
测试成员函数
// For more information, see http://www.boost.org/
#include <boost/function.hpp>
#include <iostream>
#include <functional>
struct X {
int foo(int);
};
int X::foo(int x) { return -x; }
int main()
{
boost::function2<int, X*, int> f;
f = &X::foo;
X x;
f(&x, 5);
return 0;
}