Skip to main content

Modern C++

C++ is treated in this reference as a notation in which an abstraction can be stated together with the domain on which it is valid, and in which a substantial part of the computation can be performed during translation.

The claim​

A generic component has two parts: an algorithm, and a description of the types on which that algorithm makes sense. Before C++20, only the first could be written down. The second lived in documentation, in the diagnostics produced when a substitution failed deep inside an instantiation, and in the tacit knowledge of the people maintaining the component.

Concepts move the second part into the language. The consequence is not merely better diagnostics. It is that a generic interface becomes a mathematical statement: an algorithm of type

sort:{ T∈T  :  RandomAccessRange(T)∧StrictWeakOrder(<T) }→void\mathrm{sort} : \{\,T \in \mathcal{T} \;:\; \mathrm{RandomAccessRange}(T) \land \mathrm{StrictWeakOrder}(<_T)\,\} \to \mathrm{void}

rather than a template that happens to compile for some unstated set of arguments. The domain is written, checked at the point of use, and available to overload resolution.

The remaining chapters of this part develop that position, from the language mechanisms to the translation-time sublanguage that makes them useful.

Entries​

EntrySubject
LanguageThe core model: values, objects, lifetime, initialisation, and the rules generic code relies on
TemplatesParameterisation, instantiation, deduction, specialisation, and the two-phase model
Generic ProgrammingLifting algorithms to their weakest sufficient requirements
ConceptsNamed predicates over types, and what they do and do not assert
ConstraintsNormalisation, subsumption, and partial ordering by constraint
MetaprogrammingComputation over types, and its replacement by ordinary computation over values
Compile-Time ProgrammingWhat can be evaluated during translation, and what that buys
constexpr / constevalThe evaluation model, its growth by revision, and immediate functions
Standard LibraryRanges, views, algorithms and allocators as they bear on numerical work

Revisions in this part​

Language revisions

C++20
Concepts, constrained templates, requires-expressions, ranges, consteval, constinit, three-way comparison, modules.
C++23
Deducing this, static operator(), if consteval, multidimensional subscript, a larger constexpr subset, std::mdspan.
C++26
Static reflection, expansion statements, contracts, std::simd, senders and receivers.P2996, P3068, P2900, P1928, P2300

Where a facility is available only from a later revision, the entry gives the portable formulation as well, and states what is lost by using it.