0

I am helping with some effort of improving the build speed of a big c++ project.

One of the issues is that different set of includes my result in different execution code if template specializations are involved - based on if they are visible or not.

I am trying to create a practice (rule) that will prevent such issues.

The rule I am having right now is:

Template specialization has to be either in the same header file with the template or in the header of one of the types involved in the specialization.

This seems to me that it will be sufficient to make sure that if specialization is usable - it will be always visible whatever subset of headers are included.

My question is - do you see any flaw in such rule?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
gsf
  • 6,612
  • 7
  • 35
  • 64
  • 1
    Sounds as if it would work, but the question is, is it really practical? What if I wanted to specialize the template for some existing type where I can't change the header? – Cheers and hth. - Alf Apr 02 '16 at 18:10
  • @Cheersandhth.-Alf Most of the coding rules and practices are giving up some freedom that is provided by the language to be able to achieve something else that is considered more valuable. If there is such case - you will need to find another solution for your problem. Like inheriting the class that you cannot change the header and specialize for the new class or something. This though seems an extremely theoretical problem that I doubt will be hit in practice. – gsf Apr 03 '16 at 02:43

0 Answers0