mardi 26 mai 2015

How do I prevent implicit template instantiations for a specific template?

I'd like to prevent all implicit template instantiations for a specific templated class in order to prevent it from being instantiated into every translation unit.

It looks like my options are:

  1. Use -fno-implicit-templates on gcc's command line. This suppresses all implicit template instantiations, and is not what I want. I only want to prevent it for a single template.
  2. Use C++11 "extern template". But this only suppresses specific explicit instantiations. I don't want to type out an "extern template" line for every potential template parameter list this template might be instantiated with.

So I need something in-between. It would be nice to have something like:

 extern template class Foo; // suppress all implicit instantiations of Foo

Any ideas?

Aucun commentaire:

Enregistrer un commentaire