libsigc++  3.6.0
Functions
mem_fun()

mem_fun() creates a functor from a pointer to a method. More...

Functions

template<typename T_return , typename T_obj , typename T_obj2 , typename... T_arg>
decltype(auto) sigc::mem_fun (T_obj & obj, T_return(T_obj2::* func)(T_arg...))
 Creates a functor of type sigc::bound_mem_functor which encapsulates a method and an object instance. More...
 
template<typename T_return , typename T_obj , typename... T_arg>
decltype(auto) sigc::mem_fun (T_return(T_obj::* func)(T_arg...))
 Creates a functor of type sigc::mem_functor which wraps a method. More...
 

Detailed Description

mem_fun() creates a functor from a pointer to a method.

Optionally, a reference to an object can be bound to the functor.

Note
If the object type inherits from sigc::trackable, and the functor returned from mem_fun() is assigned to a sigc::slot, the functor will be automatically cleared when the object goes out of scope. Invoking that slot will then have no effect and will not try to use the destroyed instance.
Example:
struct foo : public sigc::trackable
{
void bar(int) {}
};
foo my_foo;
sigc::slot<void(int)> sl = sigc::mem_fun(my_foo, &foo::bar);
// Note: f is not a slot. It will not be invalidated when my_foo is deleted.
auto f = sigc::mem_fun(my_foo, &foo::bar); // Usually not what you want.
decltype(auto) mem_fun(T_return(T_obj::*func)(T_arg...))
Creates a functor of type sigc::mem_functor which wraps a method.
Definition: mem_fun.h:188
Base class for objects with auto-disconnection.
Definition: trackable.h:118

For const methods mem_fun() takes a const reference or pointer to an object.

Example:
struct foo : public sigc::trackable
{
void bar(int) const {}
};
const foo my_foo;
sigc::slot<void(int)> sl = sigc::mem_fun(my_foo, &foo::bar);

If the member function pointer is to an overloaded type, you must specify the types using template arguments.

Example:
struct foo : public sigc::trackable
{
void bar(int) {} // choose this one
void bar(float) {}
void bar(int, int) {}
};
foo my_foo;
sigc::slot<void(int)> sl = sigc::mem_fun1<void, foo, foo, int>(my_foo, &foo::bar);

Function Documentation

◆ mem_fun() [1/2]

template <typename T_return , typename T_obj , typename T_obj2 , typename... T_arg>
decltype(auto) sigc::mem_fun ( T_obj &  obj,
T_return(T_obj2::*)(T_arg...)  func 
)
inline

Creates a functor of type sigc::bound_mem_functor which encapsulates a method and an object instance.

Creates a functor of type sigc::bound_const_volatile_mem_functor which encapsulates a method and an object instance.

Creates a functor of type sigc::bound_volatile_mem_functor which encapsulates a method and an object instance.

Creates a functor of type sigc::bound_const_mem_functor which encapsulates a method and an object instance.

Parameters
objReference to object instance the functor should operate on.
funcPointer to method that should be wrapped.
Returns
Functor that executes func on invocation.

◆ mem_fun() [2/2]

template <typename T_return , typename T_obj , typename... T_arg>
decltype(auto) sigc::mem_fun ( T_return(T_obj::*)(T_arg...)  func)
inline

Creates a functor of type sigc::mem_functor which wraps a method.

Creates a functor of type sigc::const_volatile_mem_functor which wraps a const volatile method.

Creates a functor of type sigc::volatile_mem_functor which wraps a volatile method.

Creates a functor of type sigc::const_mem_functor which wraps a const method.

Parameters
funcPointer to method that should be wrapped.
Returns
Functor that executes func on invocation.