libsigc++  3.6.0
Public Member Functions | Public Attributes | List of all members
sigc::adapts< T_functor > Struct Template Reference

Base type for adaptors. More...

#include <sigc++/adaptors/adapts.h>

Inheritance diagram for sigc::adapts< T_functor >:
Inheritance graph
[legend]

Public Member Functions

 adapts (const T_functor & functor)
 Constructs an adaptor that wraps the passed functor. More...
 

Public Attributes

adaptor_type functor_
 Adaptor that is invoked from operator()(). More...
 

Detailed Description

template<typename T_functor>
struct sigc::adapts< T_functor >

Base type for adaptors.

sigc::adapts wraps adaptors, functors, function pointers and class methods. It contains a single member functor which is always a sigc::adaptor_base. The adaptor_type alias defines the exact type that is used to store the adaptor, functor, function pointer or class method passed into the constructor. It differs from T_functor unless T_functor inherits from sigc::adaptor_base.

Example of a simple adaptor:
namespace my_ns
{
template <typename T_functor>
struct my_adaptor : public sigc::adapts<T_functor>
{
//
decltype(auto)
operator()() const;
//
template <typename T_arg1>
decltype(auto)
operator()(T_arg1 arg1) const;
//
template <typename T_arg1, typename T_arg2>
decltype(auto)
operator()(T_arg1 arg1, T_arg2 arg2) const;
//
// Constructs a my_adaptor object that wraps the passed functor.
// Initializes adapts<T_functor>::functor_, which is invoked from operator()().
explicit my_adaptor(const T_functor& functor)
: sigc::adapts<T_functor>(functor) {}
};
} // end namespace my_ns
//
// Specialization of sigc::visitor for my_adaptor.
namespace sigc
{
template <typename T_functor>
struct visitor<my_ns::my_adaptor<T_functor> >
{
template <typename T_action>
static void do_visit_each(const T_action& action,
const my_ns::my_adaptor<T_functor>& target)
{
sigc::visit_each(action, target.functor_);
}
};
} // end namespace sigc
void visit_each(const T_action &action, const T_functor &functor)
This function performs a functor on each of the targets of a functor.
Definition: visit_each.h:132
The libsigc++ namespace.
Definition: connection.h:28
Base type for adaptors.
Definition: adapts.h:96
adapts(const T_functor &functor)
Constructs an adaptor that wraps the passed functor.
Definition: adapts.h:104

If you implement your own adaptor, you must also provide your specialization of sigc::visitor<>::do_visit_each<>() that will forward the call to the functor(s) your adapter is wrapping. Otherwise, pointers stored within the functor won't be invalidated when a sigc::trackable object is destroyed and you can end up executing callbacks on destroyed objects.

Your specialization of sigc::visitor<> must be in namespace sigc.

Constructor & Destructor Documentation

◆ adapts()

template <typename T_functor >
sigc::adapts< T_functor >::adapts ( const T_functor &  functor)
inlineexplicit

Constructs an adaptor that wraps the passed functor.

Parameters
functorFunctor to invoke from operator()().

Member Data Documentation

◆ functor_

template <typename T_functor >
adaptor_type sigc::adapts< T_functor >::functor_
mutable

Adaptor that is invoked from operator()().