Basically I would like to have a static array of pointers to template classes. A sort of map from or lookup table where to an index corresponds a template class. II'll try to explain my question better with the code example below.
#include <iostream>
struct TemplateInterface
{
virtual int get() = 0;
};
template<int I>
struct TemplatedStruct : public TemplateInterface
{
int get() override { return I; }
};
// --------------------------------------------------------------------------
// Refactor this section with metaprogramming so to have classes from 1 to N
// --------------------------------------------------------------------------
static TemplatedStruct<1> one;
static TemplatedStruct<2> two;
static TemplatedStruct<3> three;
static TemplateInterface* TIArray[3] = {&one, &two, &three};
// --------------------------------------------------------------------------
int main() {
for(int i = 0; i < 3; ++i)
{
TemplateInterface* ptr = TIArray[i];
std::cout << ptr->get() << std::endl;
}
}