I have a set of types related with a one-to-one relation, for example:
TypeA ---> Type1
TypeB ---> Type2
TypeC ---> Type3
I know these relation at compile time.
Then, I have a template class that depends on this two types:
template<class T1,class T2>
class MyClass
{
T1 foo;
T2 bar;
};
Now, the user of my library will type something like:
MyClass<TypeA,Type1> x;
This is inconvenient because there is a dependency between the two types and it should be enough for the user specify only the first type.
Also, mixing the two types shouldn’t be possible:
MyClass<TypeA,Type2> y; //it should not compile
I am not very familiar with template meta programming, I got the impression that this is doable task, but I may be wrong.
The number of types involved is big, however I am happy to run a script to generate the code if necessary.
Do you know if it is possible or I am wasting my time? Do you have any ideas to point me on the right direction?
1 Answer