繁体   English   中英

专门用于可变参数的 class 模板

[英]Specialize class template for variadic parameters

我想为可变参数专门设计一个 class 模板:

template <typename... Ts>
struct TypeList
{
};

template <typename T>
class Foo
{
};

//Is next "specialization" even possible?
template <typename... Ts>
class Foo<TypeList<Ts...>>
{
};

Foo<TypeList<int, int>> i1{}; // OK
Foo<int, int> i2{}; // NOK:  error: wrong number of template arguments (2, should be 1)

我希望Foo的用户可以在提供TypeList或显式类型列表之间进行选择。

您可以做什么,以允许两种语法:

template <typename ... Ts>
class Foo : Foo<TypeList<Ts...>>
{
};

// Specialization
template <typename ... Ts>
class Foo<TypeList<Ts...>>
{
// ...
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM