jeudi 26 avril 2018

Generate a variadic list at runtime

Let's say I want to handle square mesh grids of N_DIMS dimensions, each of N_RES elements length, which turns out in N_ELEMS = std::pow(N_RES, N_DIMS) elements.

The implementation I had to follow is a generalization for non-squared grids

template<typename T, size_t... DIMS>
class MeshGrid
{
   // ... etc etc
}

Such as a possible instance with 3 dimensions of respectively 4, 5, 6 elements could be

 MeshGrid<float, 4, 5, 6> mg; // call A

Now I like to adapt it to something like

template<typename T, size_t RES, size_t... DIMS>
class MeshSquare
{
   // ... etc etc
}

Preserving the MeshGrid inner DIMS logic, in order to do run-time calls such as B

int res = 4, dims = 2
MeshSquare<float, res, ??dims??> // call B

For an example square mesh of 2 dimensions, 4 elements each = 16 total elements.

I'm honestly suspicious about what I'd like to do; I have the feeling that variadic lists must be handled at compilation time; the B call above is a nonsense.

If it could ever be possible, my question is how to expand dims to fit B call.

Aucun commentaire:

Enregistrer un commentaire