libsigc++  2.10.2
Modules | Classes | Macros | Functions
Functors

Functors are copyable types that define operator()(). More...

Modules

 Slots
 Slots are type-safe representations of callback methods and functions. A slot can be constructed from any function object or function, regardless of whether it is a global function, a member method, static, or virtual.
 
 mem_fun()
 mem_fun() Creates a functor from a pointer to a method.
 
 ptr_fun()
 ptr_fun() is used to convert a pointer to a function to a functor. If the 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.
 

Classes

class  sigc::can_deduce_result_type_with_decltype< T_functor >
 Helper class, to determine if decltype() can deduce the result type of a functor. More...
 
struct  sigc::functor_base
 A hint to the compiler. More...
 
struct  sigc::functor_trait< T_functor, I_derives_functor_base, I_can_use_decltype >
 Trait that specifies the return type of any type. More...
 
struct  sigc::visitor< T_functor >
 sigc::visitor<T_functor>::do_visit_each() performs a functor on each of the targets of a functor. More...
 

Macros

#define SIGC_FUNCTOR_TRAIT(T_functor, T_return)
 Helper macro, if you want to mix user-defined and third party functors with libsigc++. More...
 
#define SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
 Helper macro, if you want to mix user-defined and third party functors with libsigc++. More...
 
#define SIGC_FUNCTORS_HAVE_RESULT_TYPE
 Helper macro, if you want to mix user-defined and third party functors with libsigc++. More...
 

Functions

template<class T_action , class T_functor >
void sigc::visit_each (const T_action& _A_action, const T_functor& _A_functor)
 This function performs a functor on each of the targets of a functor. More...
 
template<class T_type , class T_action , class T_functor >
void sigc::visit_each_type (const T_action& _A_action, const T_functor& _A_functor)
 This function performs a functor on each of the targets of a functor limited to a restricted type. More...
 

Detailed Description

Functors are copyable types that define operator()().

Types that define operator()() overloads with different return types are referred to as multi-type functors. Multi-type functors are only partially supported in libsigc++.

Closures are functors that store all information needed to invoke a callback from operator()().

Adaptors are functors that alter the signature of a functor's operator()().

libsigc++ defines numerous functors, closures and adaptors. Since libsigc++ is a callback library, most functors are also closures. The documentation doesn't distinguish between functors and closures.

The basic functor types libsigc++ provides are created with ptr_fun() and mem_fun() and can be converted into slots implicitly. The set of adaptors that ships with libsigc++ is documented in the Adaptors module.

If you want to mix user-defined and third party functors with libsigc++, and you want them to be implicitly convertible into slots, libsigc++ must know the result type of your functors. There are different ways to achieve that.

If all these ways to deduce the result type fail, void is assumed.

With libsigc++ versions before 2.6, the macro SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE activated the test with decltype(). That macro is now unneccesary and deprecated.

Macro Definition Documentation

◆ SIGC_FUNCTOR_TRAIT

#define SIGC_FUNCTOR_TRAIT (   T_functor,
  T_return 
)

Helper macro, if you want to mix user-defined and third party functors with libsigc++.

If you want to mix functors not derived from sigc::functor_base with libsigc++, and these functors don't define result_type, use this macro inside namespace sigc to expose the return type of the functors like so:

namespace sigc {
SIGC_FUNCTOR_TRAIT(first_functor_type, return_type_of_first_functor_type)
SIGC_FUNCTOR_TRAIT(second_functor_type, return_type_of_second_functor_type)
...
}

◆ SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE

#define SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE

Helper macro, if you want to mix user-defined and third party functors with libsigc++.

If you want to mix functors not derived from sigc::functor_base with libsigc++, and your compiler can deduce the result type of the functor with the C++11 keyword decltype, use this macro inside namespace sigc like so:

Functors with overloaded operator()() are not supported.

Since libsigc++ 2.2.11:
Deprecated:
This macro does nothing. The test it activated in libsigc++ versions before 2.6, is now unconditionally activated.

◆ SIGC_FUNCTORS_HAVE_RESULT_TYPE

#define SIGC_FUNCTORS_HAVE_RESULT_TYPE

Helper macro, if you want to mix user-defined and third party functors with libsigc++.

If you want to mix functors not derived from sigc::functor_base with libsigc++, and these functors define result_type, use this macro inside namespace sigc like so:

Function Documentation

◆ visit_each()

template <class T_action , class T_functor >
void sigc::visit_each ( const T_action &  _A_action,
const T_functor &  _A_functor 
)

This function performs a functor on each of the targets of a functor.

◆ visit_each_type()

template <class T_type , class T_action , class T_functor >
void sigc::visit_each_type ( const T_action &  _A_action,
const T_functor &  _A_functor 
)

This function performs a functor on each of the targets of a functor limited to a restricted type.

SIGC_FUNCTOR_TRAIT
#define SIGC_FUNCTOR_TRAIT(T_functor, T_return)
Helper macro, if you want to mix user-defined and third party functors with libsigc++.
Definition: functor_trait.h:188
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
#define SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
Helper macro, if you want to mix user-defined and third party functors with libsigc++.
Definition: functor_trait.h:223
sigc
The libsigc++ namespace.
Definition: connection.h:24
SIGC_FUNCTORS_HAVE_RESULT_TYPE
#define SIGC_FUNCTORS_HAVE_RESULT_TYPE
Helper macro, if you want to mix user-defined and third party functors with libsigc++.
Definition: functor_trait.h:165