what does this ... (three dots) means in c++

C++

C++ Problem Overview


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

https://stackoverflow.com/questions/35334752/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/

C++ Solutions


Solution 1 - C++

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 )... )
{
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmansView Question on Stackoverflow
Solution 1 - C++TrevirView Answer on Stackoverflow