Reputation: 3727
Why there is no specific type allowed in a variadic template pack?
template< typename T >
class Foo
{
public:
template< typename... Values >
void bar( Values... values )
{
}
template< T... values > <-- syntax error
void bar( T... values )
{
}
template< int... values > <-- syntax error
void bar( int... values )
{
}
};
Whats the rationale in not allowing this?
Are there proposals for this?
Note: alternatives would be
std::initializer_list< T >
without narrowing of types and the { }
-brace-syntaxUpvotes: 7
Views: 3468
Reputation: 55425
It IS allowed, actually, you're just using it wrong. T...
and int...
are non-type parameter packs and their elements are values, so you can't use them as type specifiers (and you can't deduce them from a function call).
An example of correct usage:
template<int... Is>
struct IntPack {};
IntPack<1,2,3> p;
or
template< typename T >
struct Foo
{
template< T... Ts>
void bar()
{
}
};
int main()
{
Foo<int> f;
f.bar<1,2,3>();
}
Another example would be std::integer_sequence
.
Upvotes: 8