zero length variadic expansion of ill-formed call

佐手、 提交于 2019-12-10 21:46:38

问题


Question for standard gurus.

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

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)[.

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.

But when std::get<I>(a) is expanded through an empty variadic pack?

I mean: the following code

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

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?


回答1:


[temp.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
  • [...]


来源:https://stackoverflow.com/questions/46474889/zero-length-variadic-expansion-of-ill-formed-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!