格式错误的呼叫的零长度可变参数展开 [英] zero length variadic expansion of ill-formed call
问题描述
标准大师的问题.
尝试回应另一个问题,我开始怀疑代码的格式是否正确.
Trying to respond to another question, I came to doubt about the well-formedness of a code.
据我所知,以下代码格式错误
As far I know, the following code is ill-formed
int main ()
{
std::tuple<> a;
std::get<0>(a);
}
由于t
是std::tuple<Ts...>
时对std::get<I>(t)
的调用在I
超出[0, sizeof...(Ts)[
范围时是错误的.
because a call to std::get<I>(t)
, when t
is a std::tuple<Ts...>
, is ill-formed when I
is outside the range [0, sizeof...(Ts)[
.
在这种情况下,sizeof...(Ts)
为零,因此范围[0, 0[
为空,因此对于每个索引I
,std::get<I>(a)
都是错误的.
In this case sizeof...(Ts)
is zero, so the range [0, 0[
is empty, so std::get<I>(a)
is ill-formed for every index I
.
但是当std::get<I>(a)
通过一个空的可变参数包展开时?
But when std::get<I>(a)
is expanded through an empty variadic pack?
我的意思是:以下代码
#include <tuple>
template <typename ... Args>
void bar (Args const & ...)
{ }
template <std::size_t ... I>
void foo ()
{
std::tuple<> a;
bar( std::get<I>(a) ... );
}
int main ()
{
foo<>();
}
使用格式错误的(?)调用(std::get<I>(a)
)但零时间可变参数扩展(sizeof...(I)
为零),格式正确还是格式错误?
that uses a ill-formed (?) call (std::get<I>(a)
) but zero-time variadic expanded (sizeof...(I)
is zero), is well-formed or ill-formed?
推荐答案
.res]/8 :
该程序格式错误,如果出现以下情况,则无需进行诊断:
The program is ill-formed, no diagnostic required, if:
- [...]
- 可变参数模板的每个有效专业化都需要一个空的模板参数包,或者
- [...]
- [...]
- every valid specialization of a variadic template requires an empty template parameter pack, or
- [...]
这篇关于格式错误的呼叫的零长度可变参数展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!