Allan
Allan

Reputation: 4710

What is the prototype for Boost::signals2::signal::connect

I would like to encapsulate a signals2::signal object ans expose the connect and operator() functions, but how does their prototypes look like?

Example:

#include <boost/signals2/signal.hpp>

template<typename T> class A {
    public:
        typedef boost::signals2::signal<T> SIG_T;

        void connect( TYPE1 arg ){
            s.connect(arg);
        }

        void fire ( TYPE2 arg ){
            s(arg);
        }

    private:
        SIG_T s;
};

So how to express the correct type for TYPE1 and TYPE2, I assume it is something like SIG_T::???

Upvotes: 2

Views: 771

Answers (2)

Mike Seymour
Mike Seymour

Reputation: 254531

connect takes typename SIG_T::slot_type const &.

operator() takes typename SIG_T::argument_type (also defined as typename SIG_T::arg<0>::type).

Alternatively, you could use templates to avoid worrying about the exact definition and accept anything convertible to the correct types:

template <typename Slot> void connect(Slot const & slot) {s.connect(slot);}
template <typename Arg> void fire(Arg const & arg) {s(arg);}

Upvotes: 2

ildjarn
ildjarn

Reputation: 62975

The signal class synopsis is here, including the signatures of the signal::connect overloads.

Upvotes: 0

Related Questions