Chapter 2. Function Templates
This chapter introduces function templates. Function templates are functions that are parameterized so that they represent a family of functions.
2.1 A First Look at Function Templates
Function templates provide a functional behavior that can be called for different types. In other words, a function template represents a family of functions. The representation looks a lot like an ordinary function, except that some elements of the function are left undetermined: These elements are parameterized. To illustrate, let’s look at a simple example.
2.1.1 Defining the Template
The following is a function template that returns the maximum of two values:
// basics/max.hpp template <typename T> inline T const& max (T const& ...
Get C++ Templates: The Complete Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.