I'm trying to create a variadic template class that looks like this :
template <class... Args>
class Message
{
private:
std::function<void(Args...)> _function;
public:
//stuff
};
I want to have an option to bind so the user can bind any function (with corresponding arguments) when he wants. I've tried this approach (this function is a part of the Message
class, so Args...
comes from the template argument of the class):
template<class T>
void Message::bindFunction(void(T::*function)(Args... args), T* ownerPtr)
{
//This doesn't work
_function = boost::bind(function,args, ownerPtr);
}
However the above doesn't work, I've tried to create the tuple from the args in the bind function, but the compiler keeps saying:
<args_0> undeclared identifier.
(If I pass more arguments it changes)
From the user's point of view it should look like this:
class Foo
{
public:
void test2(int a, float b, double c)
{
std::cout << "bla";
}
};
int main()
{
Foo f;
Message<int,float,double> Mess;
Mess.bindFunction(&Foo::test2, &f);
}
I've seen a lot of articles talking about forwarding the parameters, however most of the answers confuse me more than I am already with different template structures without explaining them.