两个可变模板的单个功能? [英] Two variadic templates for a single function?

查看:122
本文介绍了两个可变模板的单个功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++ 11中,有可能为单个函数有两个可变参数模板?

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

如果没有,是否有一个窍门: / p>

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)


推荐答案

这完全合法:

#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;
}

这篇关于两个可变模板的单个功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆