I have a class, called DynamicTexture that takes in the width and height of a texture as template parameters. The parameters are used to instantiate a fixed size table (which is also a template class).
In my case, I am instantiating the DynamicTexture for various powers of two width/height (so 2×2, 4×4, 8×8, 16×16, 32×32 etc. all the way to 4096×4096). That means I have a lot of declarations like this:
DynamicTexture<2, 2> dTexture2;
DynamicTexture<4, 4> dTexture4;
...
DynamicTexture<4096, 4096> dTexture4096;
Now the question is, can I automate that process somehow? Furthermore, I am selecting the approxiate dTexture by quering a variable of type unsigned int (which shows the current size selected by the user) and then displaying the texture:
if (currTexSize == 2) dTexture2->show();
else if (currTexSize == 4) dTexture4->show();
...
else { dTexture4096->show(); }
Again, any way to avoid the long list of if statements?
NOTE: I am not sure how to phrase the title for this particular question. Feel free to re-word it.
You can do it with some advanced metaprogramming tricks:
then you would create an object of type
textures_holder< 1, 1 >and get a variable for each of the power of 2 dimensions up to 4096.