libsigc++: sigc::adapts< T_functor > Struct Template Reference

libsigc++ 2.12.1

Public Types | Public Member Functions | Public Attributes | List of all members
sigc::adapts< T_functor > Struct Template Reference
Adaptors

Base type for adaptors. More...

`#include <sigc++/adaptors/adaptor_trait.h>`

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

## Public Types
typedef adaptor_trait< T_functor >::adaptor_type | adaptor_type
typedef adaptor_trait< T_functor >::result_type | result_type

## Public Member Functions
| adapts (const T_functor & _A_functor)
| Constructs an adaptor that wraps the passed functor.

## Public Attributes
adaptor_type | functor_
| Adaptor that is invoked from operator()().

## Detailed Description

template<class 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 typedef adaptor_type 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 <class T_functor>
  struct my_adaptor : public sigc::adapts<T_functor>
  {
  template <class T_arg1=void, class T_arg2=void>
  struct deduce_result_type
  { typedef sigc::deduce_result_t<T_functor, T_arg1, T_arg2> type; };
  typedef typename sigc::functor_trait<T_functor>::result_type result_type;
  //
  result_type
  operator()() const;
  //
  template <class T_arg1>
  typename deduce_result_type<T_arg1>::type
  operator()(T_arg1 _A_arg1) const;
  //
  template <class T_arg1, class T_arg2>
  typename deduce_result_type<T_arg1, T_arg2>::type
  operator()(T_arg1 _A_arg1, T_arg2 _A_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& _A_functor)
  : sigc::adapts<T_functor>(_A_functor) {}
  };
  } // end namespace my_ns
  //
  // Specialization of sigc::visitor for my_adaptor.
  namespace sigc
  {
  template <class T_functor>
  struct visitor<my_ns::my_adaptor<T_functor> >
  {
  template <class T_action>
  static void do_visit_each(const T_action& _A_action,
  const my_ns::my_adaptor<T_functor>& _A_target)
  {
  sigc::visit_each(_A_action, _A_target.functor_);
  }
  };
  } // end namespace sigc
  sigc::visit_each
  void 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.
  Definition visit_each.h:169
  sigc
  The libsigc++ namespace.
  Definition limit_reference.h:12
  sigc::deduce_result_t
  typename deduce_result_type< T_functor, T_args... >::type deduce_result_t
  Definition deduce_result_type.h:68
  sigc::adapts
  Base type for adaptors.
  Definition adaptor_trait.h:387
  sigc::deduce_result_type
  Deduce the return type of a functor.
  Definition deduce_result_type.h:50
  sigc::deduce_result_type::type
  decltype(test< T_functor >()) type
  Definition deduce_result_type.h:64
  sigc::result_type
  sigc::functor_trait::result_type
  void result_type
  Definition functor_trait.h:135
  sigc::type
  sigc::visitor
  sigc::visitor<T_functor>::do_visit_each() performs a functor on each of the targets of a functor.
  Definition visit_each.h:156
  sigc::visitor::do_visit_each
  static void do_visit_each(const T_action &_A_action, const T_functor &_A_functor)
  Definition visit_each.h:158

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.

## Member Typedef Documentation

## ◆ adaptor_type

template <class T_functor>

typedef adaptor_trait<T_functor>::adaptor_type sigc::adapts< T_functor >::adaptor_type

## ◆ result_type

template <class T_functor>

typedef adaptor_trait<T_functor>::result_type sigc::adapts< T_functor >::result_type

## Constructor & Destructor Documentation

## ◆ adapts()

template <class T_functor>

sigc::adapts< T_functor >::adapts | ( | const T_functor & | _A_functor | ) |
| inlineexplicit

Constructs an adaptor that wraps the passed functor.

Parameters

  _A_functor | Functor to invoke from operator()().

## Member Data Documentation

## ◆ functor_

template <class T_functor>

adaptor_type sigc::adapts< T_functor >::functor_
| mutable

Adaptor that is invoked from operator()().