title: C++ Templates: Are template ínstantiations inlined? Are there drawbacks in performance?
body: <p>When some C++ entity, such as a structure, class, or function, is declared as a template, then the definitions provided for said entities are solely blue-prints which must be instantiated.</p>
  
  <p>Due to the fact that a template entity must be defined when it is declared (which is commonly header files) I have the conception, which I try to convince myself as wrong, that when after a template has been instantiated it will be inlined by the compiler. I would like to ask if this is so?</p>
  
  <p>The answer for this <a href="https://stackoverflow.com/questions/266523/drawbacks-to-templates-and-the-stl-in-c">question</a> raises my suspicion when I read the the paragraph: </p>
  
  <blockquote>
    <p>"Templates can lead to slower compile-times and possibly larger
    executable, especially with older compilers."</p>
  </blockquote>
  
  <p>Slower compile-times are clear as template must be instantiated but why "possibly larger executables"? In what ways should this be interpreted? Should I interpret this as 'many functions are inlined' or 'the executable's size increases if there are many template instantiations, that is the same template is instantiated with a lot of different types, which causes several copies of the same entity to be there'?</p>
  
  <p>In the latter case, does a larger executable size cause the software to run more slowly seeing that more code must be loaded into memory which will in turn cause expensive paging?</p>
  
  <p>Also, as these questions are also somewhat compiler dependent I am interested in the Visual C++ compiler. Generalised answers concerning what most compilers do give a good insight as well.</p>
  
  <p>Thank you in advance.</p>