In C++, templates are a feature that supports generic programming (code that is more type-independent). The template prefix is given by template <class T> (where is a type parameter that can change).

template<class T, class T_2> // must be put before every function or class
void swap (T& left, T& right) {
	T temp;
	// etc
}

Templates generally increase compilation time (though it’s questionable how significant this can get). The compiler generally builds a new type-specific version every time it’s called.

C++ doesn’t allow separation of interface and implementation for template definitions so they must be included with the code that uses it. Some approaches: 1) only have a header file (or alternatively a .hpp file) and no implementation file or 2) #include the implementation file (.cpp) for the template class instead of the header file or 3) have two header files and #include one in the other.

The C++ Standard Template Library includes several templated classes implemented with methods for us. They vastly expand the language’s functionality.