65

It may seems a silly question, but when I try to look at this answer in SOF,

Compile time generated tables

I noted statements such as this:

template<
    typename IntType, std::size_t Cols, 
    IntType(*Step)(IntType),IntType Start, std::size_t ...Rs
> 
constexpr auto make_integer_matrix(std::index_sequence<Rs...>)
{
    return std::array<std::array<IntType,Cols>,sizeof...(Rs)> 
        {{make_integer_array<IntType,Step,Start + (Rs * Cols),Cols>()...}};
}

more specifically :

std::size_t ...Rs

or

std::index_sequence<Rs...>

what does ... means here?

Edit 1

The question that reported as the original question related to this question is not correct:

That question can not answer these two cases (as they are not functions with variable number of arguments)

std::size_t ...Rs
std::index_sequence<Rs...>

But this is a good explanation:

https://xenakios.wordpress.com/2014/01/16/c11-the-three-dots-that-is-variadic-templates-part/

Community
  • 1
  • 1
mans
  • 17,104
  • 45
  • 172
  • 321
  • https://xenakios.wordpress.com/2014/01/16/c11-the-three-dots-that-is-variadic-templates-part/ – Jean-François Fabre Sep 30 '16 at 13:15
  • They specify [variadic arguments](http://en.cppreference.com/w/cpp/language/variadic_arguments), see the duplicate link for how they are used. – Cory Kramer Sep 30 '16 at 13:17
  • @CoryKramer :Thanks, but they don't, as for example std::size_t ...Rs is not a function with variable number of arguments, it is a template with variable number of argument as explained in the blog. – mans Sep 30 '16 at 13:26
  • @CoryKramer Your "duplicate question" is not a complete duplicate of this, as this contains a question about variadic templates in addition to variadic arguments. – KitsuneYMG Sep 30 '16 at 13:31
  • Possible duplicate of [Non-type variadic function templates in C++11](http://stackoverflow.com/questions/7877293/non-type-variadic-function-templates-in-c11) – Ami Tavory Sep 30 '16 at 13:52

1 Answers1

55

Its called a parameter pack and refers to zero or more template parameters:

http://en.cppreference.com/w/cpp/language/parameter_pack

std::size_t ...Rs

is the parameter pack of type std::size_t. A variable of that type (e.g. Rs... my_var) can be unpacked with:

my_var... 

This pattern is heavily used in forwarding an (unknown) amount of arguments:

template < typename... T >
Derived( T&&... args ) : Base( std::forward< T >( args )... )
{
}
Trevir
  • 1,253
  • 9
  • 16