C++ function templates

A function template describes a family of functions. The compiler deduces T from matching arguments and instantiates the needed versions.

C++
#include <iostream>
template <typename T>
T maximum(T left, T right) {
    return left > right ? left : right;
}
int main() {
    std::cout << maximum(3, 7) << '\n';
    std::cout << maximum(2.5, 1.5) << '\n';
}
Read the full lesson