function with function object argument of different signatures

93 views Asked by At

I tried overloading a function with boost::function with different signatures, it did not work. I tried using template<Signature> Connection *connect(boost::function<Signature> f) which also failed because boost::bind doesn't implicitly convert that way

What I'm trying to do is exactly what boost::signals does. Boost signals can accept both, function object without arguments and function objects with N arguments

I want to know how I can accept both type of function objects in one function.

1

There are 1 answers

4
David G On

You can use variadic templates:

template<typename R, typename... Args>
Connection* connect(boost::function<R (Args...)> f);

This will accept both a function that takes 0 arguments or one that accepts N arguments.