Chapter 3

Generic Programming

“One must always try to see the truth of a situation. It makes things universal.”

—V. S. Naipaul

Templates are a feature of C++ to create functions and classes that operate on parametric (generic) types. As a result, a function or class can work with many different data types without being manually rewritten for each one.

Generic Programming is sometimes considered synonymous with template programming. But this is not correct. Generic programming is a programming paradigm aiming for maximal applicability while providing correctness. Its main tools are templates. Mathematically it is founded on Formal Concept Analysis [17]. In generic programming, the template programs contain the full set of sufficient conditions ...

Get Discovering Modern C++, 2nd Edition 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.