lundi 1 avril 2019

What's the most efficient way to access the last template parameter?

It is possible to use template parameters pack as follows:

template <int T1, int... Ts>
struct Test {
  static constexpr int sizes[] = {Ts...};
};

template <int T1, int... Ts>
constexpr int Test<T1, Ts...>::sizes[];

However, as it is detailed here, the template parameter pack must be the last template parameter. Hence, we cannot have a code such as this:

template <int T1, int... Ts, int Tn>
struct Test {
  static constexpr int sizes[] = {Ts...}; 
  Foo<Ts...> foo;
};

template <int T1, int... Ts, int Tn>
constexpr int Test<T1, Ts..., Tn>::sizes[];

In many cases, we need to have access to the last element of a set of template parameters. My question is, what's the best practice for realizing the above code?

Aucun commentaire:

Enregistrer un commentaire