Two variadic templates for a single function?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 00:43:48

问题


In C++11 is it possible to have two variadic templates for a single function ?

If not, is there a trick to write something like that :

template <class... Types, class... Args> 
void f(const std::tuple<Types...>& t, Args&&... args)

回答1:


That's perfectly legal:

#include <tuple>

using namespace std;

template <class... Types, class... Args>
void f(const std::tuple<Types...>& t, Args&&... args)
{
    // Whatever...
}

int main()
{
    std::tuple<int, double, bool> t(42, 3.14, false);
    f(t, "hello", true, 42, 1.0);

    return 0;
}


来源:https://stackoverflow.com/questions/15043527/two-variadic-templates-for-a-single-function

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