I want to efficiently multiply the arguments from a parameter package with std :: array elements:
int index(auto... Is, std::array<int,sizeof...(Is)> strides)
{
}
I can't completely wrap my brain around this. I started the sequence index path, but I could figure out how to enable summation.
I use C ++ 17, so fold statements are fair game if they simplify the code.
Thanks for any pointers.
EDIT: Refined Pseudo Code. The only pseudo-part is an expression Is[i]
that refers to the package argument of the ith parameter.
The TC answer below was perfect, and here is my final code, which is a member function:
unsigned int index(auto... indexes)
{
unsigned int idx = 0, i = 0;
(..., (idx += indexes * m_strides[i++]));
return idx;
}
Starting with this entry, code is compiled using gcc 6.3.0 with the -fconcepts flag, which introduces the concept of TS.
auto... indexes
template<typename Args> f(Args... indexes)
. unsigned int , .
(...,) - ( [] ):
idx += indexes[0] * m_strides[i++], idx += indexes[1] * m_strides[i++], etc.
, .