Templates is a historical design pattern. Template metaprogramming (TMP) is a metaprogramming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled. The output of these templates include compile-time constants, data structures, and complete functions. The use of templates can be thought of as compile-time execution. Read more on Wikipedia...

?Years Old
  • Templates ranks in the top 50% of entities I track
  • the Templates wikipedia page
  • I have 16 facts about Templates. what would you like to know? email me and let me know how I can help.

Languages with Templates include cpp, d, xl-programming-language

Example from cpp:

template <int length>
Vector<length>& Vector<length>::operator+=(const Vector<length>& rhs)
{
    for (int i = 0; i < length; ++i)
        value[i] += rhs.value[i];
    return *this;
}

Example from d:

template TCopy(T)
{
    void copy(out T to, T from)
    {
        to = from;
    }
}
int i;
TCopy!(int).copy(i, 3);

Last updated September 6th, 2019