对于每个模板类型,设置类型的参数 [英] For every template type an argument of a set type
本文介绍了对于每个模板类型,设置类型的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个可变参数模板类。我该如何创建一个函数,使其参数为设置类型,例如 int
,并且参数数量等于模板类型的数量?
Say I have a variadic template class. How do I create a function such that it's arguments are of a set type, for example int
, with the number of arguments being equal to the number of template types?
template <typename... Types>
class Test
{
public:
void Func(???); // I don't know how to declare such a function
}
Test<string, bool, long> myTest; // Three types
myTest.Func(905, 36, 123315); // Three arguments, but always of type int.
最后,该函数的目标是返回提供的int的元组。为简单起见,我在示例代码中显示了该函数为空。
In the end, the goal of the function is to return a tuple of the provided ints. For simplicity I showed the function to be void in the example code.
推荐答案
template <typename... Types>
class Test
{
template <typename>
using int_t = int;
public:
void Func(int_t<Types>... ints)
{
}
};
这篇关于对于每个模板类型,设置类型的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文