I have the following template class:
template
class T : public I
{
// ...
};
This template class need to be derived once (an
The only answer I can envision is to have a registry of instantiations and their derivatives. You could then devise a metafunction that searches the registry. You pass it the base and the derived and if you're not deriving with the registered type it returns void type or something so it causes a compiler error. Based on your requirements that the base has no knowledge of the derived this is the only remotely possible answer I can think of.
Your declarations would then look something like:
struct A : search_registry, A>::type { ... };
I believe you're going to run into many issues that will be tough to solve even here--good luck!
And remember, template metaprograms are purely functional. You can't "add" to the registry in any nice way. You're going to need to define it once to hold everything. On the plus side if someone forgets to add to the registry they'll know, or if they use a previously defined one...on the minus, this is ugly as duck.