I'd like to increment a counter for each parameter during parameter pack expansion. Here is some pseudo code of what I want to achieve:
template<class ... Args>
void doSomething(Args ... _args)
{
std::size_t counter = 0;
bar(doSomethingWithOneArg(_args, counter++)...);
}
The problem with this code is, that while the order of the Args
is preserved, the order in which the function parameters are evaluated is not defined, i.e. on clang
the order in which the counter expressions are evaluated is the same as the order of Args
while in gcc
it is reversed. What is a portable, standard way of achieving this?
Thanks!