Pass tuple's content as variadic function arguments

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 13:08:25

It should be equivalent, but the only way to be sure is to test with the compiler you are using.

Note that you could use std::function with std::bind instead, e.g. something like:

template<typename ...T_arguments> class Task : public TaskCaller
{
    std::function<bool (T_arguments&...)> functor;
public:
    Task (bool (*func)(T_arguments&...), T_arguments... arguments)
      : functor(std::bind(func, arguments...))
    {}
    bool dispatch() {
        return functor();
    }
    // ...

Or better yet, let the user pass a std::function in:

class Task : public TaskCaller {
    std::function<bool ()> functor;
public:
    Task(std::function<bool ()> func) : functor(func) {}
    // ...

That allows the user to choose what to pass instead of forcing him to use free functions or static member functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!