Aar*_*man 7 c++ variadic-templates
假设我有一个可变参数模板类.如何创建一个函数,使其参数属于集合类型,例如int,参数的数量等于模板类型的数量?
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.
Run Code Online (Sandbox Code Playgroud)
最后,该函数的目标是返回所提供的int的元组.为简单起见,我在示例代码中将函数显示为void.
Pio*_*cki 18
template <typename... Types>
class Test
{
template <typename>
using int_t = int;
public:
void Func(int_t<Types>... ints)
{
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
353 次 |
| 最近记录: |