我想专门处理可变参数的类模板:
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
还是提供明确的类型列表之间进行选择。
答案 0 :(得分:2)
您可以做什么,以允许两种语法:
template <typename ... Ts>
class Foo : Foo<TypeList<Ts...>>
{
};
// Specialization
template <typename ... Ts>
class Foo<TypeList<Ts...>>
{
// ...
};