5. Templates

Your quote here.

– B. Stroustrup

Introduction

Parameterized Types

Function Templates

Concepts and Generic Programming

Function Objects

Variadic Templates

Aliases

Template Compilation Model

Advice

5.1. Introduction

Someone who wants a vector is unlikely always to want a vector of doubles. A vector is a general concept, independent of the notion of a floating-point number. Consequently, the element type of a vector ought to be represented independently. A template is a class or a function that we parameterize with a set of types or values. We use templates to represent concepts that are best understood as something very general from which we can generate specific types and functions by specifying arguments, such ...

Get A Tour of C++ 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.