mercredi 25 février 2015

Recursively defining templates

In C++11 it is possible to explicitly create a template instanciation using



template class A<int>;


In a source file, and



extern template class A<int>;


In the header to prevent the compiler from generating an own instanciation of the template and instead link with the one in the module.


Does template class A<int>, applied on a class template, generate instanciations for all its member functions as well?


And if is has member function templates, like



template<typename T>
class A {
public:
template<typename T2>
void f();
}


Is there a way to specify that each time a A<...> template instanciation is generated, A<...>::f<int>() and A<...>::f<long>() (for example) should also be created? And the compiler encountering extern template class A<int> should know about these instanciations and link to them.


And can it also be extended to types outside the template, for example



template<typename T>
class A {
public:
using helper = A_helper<T>;
}


Each time a A<...> is instanciated, A_helper<...> is too.


Aucun commentaire:

Enregistrer un commentaire