mercredi 16 décembre 2020

get non-type template parameters into tuple

How does one construct a tuple with non type template parameters

template <auto... args>
void func()
{
  std::tuple<decltype(args)...> t(args...);
  cout << get<3>(t) << endl;
}

template <auto... args>
struct ZZ
{
  std::tuple<decltype(args)...> t(args...);
};


int main()
{
   func<1,2,3,4>();
   ZZ<1,2,3> z;
}

While it works for func it does not work for the struct and results in the compile error (gcc trunk)

vs.cc:102:35: error: ‘args’ is not a type
  102 |   std::tuple<decltype(args)...> t(args...);
      |                                   ^~~~

Aucun commentaire:

Enregistrer un commentaire