PLDB
Languages Features Calendar About Lists Add Language
GitHub icon

Templates

Templates

Templates are a language feature.

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...

Languages with Templates include C++, D, XL

Example from C++:

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);

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements · Email · GitHub