Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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/

like image 328
mans Avatar asked Sep 30 '16 13:09

mans


People also ask

What does 3 dots mean in C?

The three dots '...' are called an ellipsis. Using them in a function makes that function a variadic function. To use them in a function declaration means that the function will accept an arbitrary number of parameters after the ones already defined.

What is the function of the three dots?

An ellipsis (plural: ellipses) is a punctuation mark consisting of three dots. Use an ellipsis when omitting a word, phrase, line, paragraph, or more from a quoted passage. Ellipses save space or remove material that is less relevant.

What is the use of three dots in C Java programming language?

The "Three Dots" in java is called the Variable Arguments or varargs. It allows the method to accept zero or multiple arguments. Varargs are very helpful if you don't know how many arguments you will have to pass in the method.

What is Dot called in programming?

operator in C/C++ The dot (.) operator is used for direct member selection via object name. In other words, it is used to access the child object.


1 Answers

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 )... )
{
}
like image 175
Trevir Avatar answered Oct 18 '22 22:10

Trevir