元组作为函数参数 [英] tuple as function argument
本文介绍了元组作为函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果可能如何使用可变参数元组作为函数的参数以及如何对其进行初始化,我会感到困惑。
I am a little confused if it possible an how to use a variadic tuple as an argument in a function and how to initialize it.
template <typename T, Arg ...>
void foo (int a, std::tuple<T, sizeof(Arg)> TupleTest);
...
foo(TupleTest(2, "TEST", 5.5));
如何使用c ++ 0x来实现?
How could that be implemented using c++0x?
推荐答案
您不需要获取模板参数的数量。只需这样做:
You don't need to get the number of template arguments. Just do this:
template <typename... T>
void foo(int a, std::tuple<T...> TupleTest);
// make_tuple so we don't need to enter all the type names
foo(0, std::make_tuple(2, "TEST", 5.5));
这篇关于元组作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文