jeudi 2 avril 2015

Pass array of unknown rank by reference

I am trying to pass by reference an array of unknown number of dimensions (rank). Basically, I'd like to do something like this (which does not compile)



template <typename T, int... dims>
void f(T (&arr)[dims]...) // not working
{
}

int main()
{
int arr[2][3][4]; // rank 3
f(arr);
}


Is there any way of achieving this? In particular, is it somehow possible to use a variadic-template approach?


I can do the generic template<typename T> f(T& arr), but in this case how I'd be able to recover the sizes without explicitly passing them? (Even with a variadic template approach I'm not sure how to recover the individual elements in the pack... without some kind of recursive folding).


Aucun commentaire:

Enregistrer un commentaire