I want to specialize a class template for variadic parameters:
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)
I want that users of Foo
can choose between providing a TypeList
or an explicit list of types.
What you can do, to allow both syntaxs:
template <typename ... Ts>
class Foo : Foo<TypeList<Ts...>>
{
};
// Specialization
template <typename ... Ts>
class Foo<TypeList<Ts...>>
{
// ...
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.