C++ Language/Templates

From Wikibooks, open books for an open world
Jump to navigation Jump to search

A "template" is C++ source code that doesn't get compiled into machine language at the time it's encountered by the compiler. Instead, the compiler remembers that code. The template contains one or more template-parameters; later, the compiler will perform a compilation of that code when it first needs a "specialization" of it. That specialization involves substituting some C++ type in place of each template-parameter.

  1. Templated-Functions
  2. Templated-Classes
  3. Templated-Variables
  4. Template-Parameters
  5. Traits
  6. Metaprogramming
  7. Concepts