struct Foo { int test(int x); }; Foo * foo = ...; boost::function<int (int)> f = senf::membind(&Foo::test,foo); int rv = f(1); // Calls foo->test(1)
senf::membind() takes either a pointer or an object as second argument. When passing an object, that object will be copied into the bound member function returned.
Defines |
|
#define | SENF_FNP(ret, fn, args) |
Get function pointer. |
|
#define | SENF_MEMFNP(ret, cls, fn, args) |
Get function pointer. |
|
#define | SENF_MEMBINDFNP(ret, cls, fn, args) |
Get function pointer. |
|
Functions |
|
template<typename R , typename T , typename Args > | |
boost::function< R(Args)> | senf::membind (R(T::*fn)(Args), T *ob) |
Build bound member function object. |
#define | ||||
SENF_FNP | ( | ret, | ||
fn, | ||||
args | ) | |||
Get function pointer.
This macro will get a function pointer of a possibly overloaded function:
void foo(int i); int foo(); SENF_FNP(void, foo, (int i)) // Get the address of the first overload
The macro arguments are the return type, function name and function arguments just as specified in the declaration.
This macro only works for functions at namespace scope or for class static functions. For member functions use SENF_MEMFNP() or SENF_MEMBINDFNP().
Definition at line 80 of file membind.hh.
#define | ||||
SENF_MEMBINDFNP | ( | ret, | ||
cls, | ||||
fn, | ||||
args | ) | |||
Get function pointer.
This macro will get a member function pointer of a possibly overloaded member function and bind it to this
returning a boost::function object resembling an ordinary non-member function (see senf::membind()).
struct Foo { void foo(int i); int foo() const; Foo() { // Get bound member function for second overload SENF_MEMBINDFNP(int, Foo, foo, () const) } };
The macro arguments are the return type, class name, function name and function arguments just as specified in the declaration.
This macro only works for member functions. For namespace scope functions or class static functions use SENF_FNP.
This macro returns a bound member function (a boost::function
object instance). To get an ordinary member function pointer use SENF_MEMFNP(), for non-member function or class static functions use MEM_FNP().
Definition at line 146 of file membind.hh.
#define | ||||
SENF_MEMFNP | ( | ret, | ||
cls, | ||||
fn, | ||||
args | ) | |||
Get function pointer.
This macro will get a member function pointer of a possibly overloaded member function:
struct Foo { void foo(int i); int foo() const; }; SENF_MEMFNP(int, Foo, foo, () const) // Get the address of the first overload
The macro arguments are the return type, class name, function name and function arguments just as specified in the declaration.
This macro only works for member functions. For namespace scope functions or class static functions use SENF_FNP.
This macro returns a member function pointer. To automatically bind this pointer to this
, use SENF_MEMBINDFNP() or use senf::membind() to bind to some other instance besides this
.
Definition at line 109 of file membind.hh.
boost::function<R (Args)> senf:: | ||||
membind | ( | R(T::*)(Args) | fn, | |
T * | ob | ) | ||
Build bound member function object.
membind() supports up to 9 function parameters (represented as Args here). The ob argument can be either a pointer or a reference to T
[in] | fn | member function pointer |
[in] | ob | object instance to bind this pointer to |