Variable zero-length extension of a poorly organized call

Question for standard gurus.

Trying to answer another question , I doubted the correctness of the code.

As far as I know, the following code is poorly formed

int main ()
 {
   std::tuple<>  a;

   std::get<0>(a);
 }

because the call std::get<I>(t)when ta std::tuple<Ts...>poorly formed when Iout of range [0, sizeof...(Ts)[.

In this case, it sizeof...(Ts)is equal to zero, therefore the range is [0, 0[empty, therefore it is std::get<I>(a)poorly formed for each index I.

But when std::get<I>(a)expanded through empty variation packaging?

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

(?) (std::get<I>(a)), (sizeof...(I) ), ?

+3
1

[temp.res]/8:

, , :

  • [...]
  • [...]
+6

Source: https://habr.com/ru/post/1686684/


All Articles