C/C++ Arena

Step 1 of 8

Function templates

A template is a recipe the compiler uses to generate code for each type you use it with:

template <typename T>
T biggest(T a, T b) {
    return a > b ? a : b;
}

biggest(3, 9);             // T = int
biggest(2.5, 1.0);         // T = double
biggest<std::string>("a", "b");

Your turn: make clamp_value a template.

Next: Templates over containers