jeudi 25 juin 2015

C++ Convert a parameter pack of types to parameter pack of indices

Is there any way to convert a parameter pack of types to a parameter pack of integers from 0 to sizeof...(Types)? More specifically, I'm trying to do something this this:

template <size_t... I>
  void bar();

template <typename... Types>
  void foo() {
    bar<WHAT_GOES_HERE<Types>...>();
  }

For example, foo<int,float,double>() should call bar<0, 1, 2>();

In my use case the parameter pack Types may contain the same type multiple times, so I cannot search the pack to compute the index for a given type.

Aucun commentaire:

Enregistrer un commentaire