Clone wiki

sigfwd / supported_functors

Supported functor and function types

Without having to do anything, sigfwd is able to deduce the call signatures of:

  • regular C++ functions (and pointers and references thereto)
  • C++ standard-library-style unary and binary functors i.e. those that expose an argument_type or a first_argument_type and a second_argument_type. This includes things like std::ptr_fun, std::bind1st, and so on
  • any functor that has and exposes a single (not-overloaded) non-template function call operator (operator())

Additional signature deduction support is provided for many of the functors provided by boost. To access this support you can either include the <sigfwd/sigfwd.hpp>, which brings in everything the library has to offer, or you can use one of the more fine-grained headers:

#include <sigfwd/support/boost/bind.hpp>
#include <sigfwd/support/boost/signals.hpp>
#include <sigfwd/support/boost/signals2.hpp>
#include <sigfwd/support/boost/function.hpp>

Unfortunately, I believe it's impossible to deduce a call signature for a boost::lambda expression. You'll have to use sigfwd::connectx and specify the expression's call signature yourself.

At this point boost::mem_fn isn't supported, but it's functionality is subsumed by boost::bind anyway.

A note about boost::signals support

Qt by default defines a signals pre-processor macro. This can cause code using boost::signals to fail to compile.

For this reason, if a signals preprocessor macro is defined, including <sigfwd/support/boost/signals.hpp> will output a warning message and boost::signals support will remain disabled.

To get Qt and boost::signals to play nice, refer to the Qt documentation for information on the no_keywords feature in qmake and the Q_SIGNALS macro.

Note that there is no such problem with the boost::signals2 library.

Adding support for your own functors (advanced)

If you have a functor that doesn't fall under the support offered in sigfwd by default, you can specialize the sigfwd::functor_traits template for your functor type.

functor_traits is declared in <sigfwd/functor_traits.hpp>.

When your specialization is instantiated with your functor type, it must expose two things:

  1. a boost MPL sequence containing the parameter types of the functor, called params
  2. a static integral constant called arity, that is equal to the number of elements in params

If you can obtain a call signature from your functor, the easiest way to implement a functor_traits specialization is to derive from functor_traits_from_call_sig<CallSig>. For example, here is how boost::function<> is supported:

#include <sigfwd/functor_traits.hpp>

namespace sigfwd
    template<typename Sig>
    struct functor_traits<boost::function<Sig> > :