Bound Member Functions

Macros

#define SENF_FNP(ret, fn, args)
 Get function pointer. More...
 
#define SENF_MEMFNP(ret, cls, fn, args)
 Get function pointer. More...
 
#define SENF_MEMBINDFNP(ret, cls, fn, args)
 Get function pointer. More...
 

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. More...
 

Detailed Description

The membind() family of function templates simplifies the creation of simple bound member function pointers:

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,
<em>that object will be copied into the bound member function returned.</em>
Idea:
Make the ob argument type an additional P template parameter (using call_traits for the exact arg type? Probably we'll get deduction problems then) . The only operation this object must support is ob->*fn. This would allow the use of smart pointers. We should keep the T & version to still support ob.*fn use.

Macro Definition Documentation

◆ SENF_FNP

#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 \ref SENF_MEMFNP() or \ref SENF_MEMBINDFNP().

Definition at line 71 of file membind.hh.

◆ SENF_MEMBINDFNP

#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 \c boost::function object instance). To get an
ordinary member function pointer use \ref SENF_MEMFNP(), for non-member function or class static
functions use \ref MEM_FNP().

Definition at line 137 of file membind.hh.

◆ SENF_MEMFNP

#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 \c this, use
\ref SENF_MEMBINDFNP() or use senf::membind() to bind to some other instance besides \c this.

Definition at line 100 of file membind.hh.

Function Documentation

◆ membind()

template<typename R , typename T , typename Args >
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

Parameters
[in]fnmember function pointer
[in]obobject instance to bind this pointer to
Returns
Boost.Function object representing a bound call of fn on ob