这是什么...(三点)在c ++中是什么意思 [英] what does this ... (three dots) means in c++

查看:116
本文介绍了这是什么...(三点)在c ++中是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,但是当我尝试在SOF中查看此答案时,

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

Compile time generated tables

我注意到这样的语句:

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>()...}};
}

更具体地说:

std::size_t ...Rs

std::index_sequence<Rs...>

这里的意思是什么?

作为与该问题相关的原始问题报告的问题不正确:

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-the-is-variadic-templates-part /

推荐答案

它称为参数包,指的是零个或多个模板参数:

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

是类型为<$的参数包c $ c> std :: size_t 。
该类型的变量(例如 Rs ... my_var )可以用以下命令解包:

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

这篇关于这是什么...(三点)在c ++中是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆