libsigc++: mem_fun()

libsigc++ 3.0.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

Functions
mem_fun()
Functors

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

## Functions
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...
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...

## Detailed Description

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

Optionally, a reference or pointer 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.

If the member function pointer is to an overloaded type, you must specify the types using template arguments starting with the first argument. It is not necessary to supply the return type.

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.

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);

Use mem_fun#() if there is an ambiguity as to the number of arguments.

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

## Function Documentation

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

  func | Pointer to method that should be wrapped.

Returns
  Functor that executes func on invocation.

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

  obj | Reference to object instance the functor should operate on.
  func | Pointer to method that should be wrapped.

Returns
  Functor that executes func on invocation.