0

I've been searching the most simple and elegant solution and found this:

#include <iostream>
#include <utility>
#include <tuple>


struct A{
  void hi(){
    std::cout << "HI\n";
  }
};

template<typename Tuple, std::size_t... Is>
void unpack(Tuple& tpl, std::index_sequence<Is...>){
  ((std::get<Is>(tpl).hi()),...);
}

int main(){

  std::tuple<A,A,A,A,A,A> tpl { A(), A(), A(), A(), A(), A() };

  unpack(tpl, std::make_index_sequence<6>{});

  return 0;
}

However, i do not completely understand this line:

((std::get<Is>(tpl).hi()),...);

I understand what it does, but what is that kind of syntax?

Is it somewhere in standard?

toozyfuzzy
  • 1,080
  • 1
  • 9
  • 20

1 Answers1

0

This is a fold expression that does

(std::get<Is>(tpl).hi())

for every Is that is packed inside.

Poeta Kodu
  • 1,120
  • 8
  • 16