jeudi 23 avril 2015

Alternative to "extern template" in every source file

I'm working on a library where many of our core objects are templates with one particular instantiation showing up in most of the files in the project in the form of a smart pointer to that template instantiation. I explicitly instantiate these templates in a single source file. We recently switched to C++11 and I'm trying to use the new

extern template class MyTemplate<double>;

to speed up the compilation. My first question is whether my use of smart pointers around

MyTemplate<double>

is implicitly instantiating the template and requires the "extern template .." at the top of the file to avoid duplicate instantiation.

My second question is whether there is some alternative to adding all these

extern template class MyTemplate<double>;

to every source file. It just gets a little tedious grepping every instance of the smart pointer for every template I define and making sure I have the correct "extern template" line in that file. I can also see it being a little difficult to enforce this convention for future developers of our code as they may add a template instantiation and forget the appropriate extern template line, especially since no error will be generated.

Aucun commentaire:

Enregistrer un commentaire