这是什么...(三个点)在 C++ 中意味着什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39792417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does this ... (three dots) means in c++
提问by mans
It may seems a silly question, but when I try to look at this answer in SOF,
这似乎是一个愚蠢的问题,但是当我尝试在 SOF 中查看此答案时,
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
编辑 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/
https://xenakios.wordpress.com/2014/01/16/c11-the-three-dots-that-is-variadic-templates-part/
采纳答案by Trevir
Its called a parameter pack and refers to zero or more template parameters:
它称为参数包,指的是零个或多个模板参数:
http://en.cppreference.com/w/cpp/language/parameter_pack
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:
是类型的参数包std::size_t
。该类型的变量(例如Rs... my_var
)可以通过以下方式解包:
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 )... )
{
}