English

Concept-Based Generic Programming in C++

Programming Languages 2025-10-13 v1 Software Engineering

Abstract

We present programming techniques to illustrate the facilities and principles of C++ generic programming using concepts. Concepts are C++'s way to express constraints on generic code. As an initial example, we provide a simple type system that eliminates narrowing conversions and provides range checking without unnecessary notational or run-time overheads. Concepts are used throughout to provide user-defined extensions to the type system. The aim is to show their utility and the fundamental ideas behind them, rather than to provide a detailed or complete explanation of C++'s language support for generic programming or the extensive support provided by the standard library. Generic programming is an integral part of C++, rather than an isolated sub-language. In particular, key facilities support general programming as well as generic programming (e.g., uniform notation for types, lambdas, variadic templates, and C++26 static reflection). Finally, we give design rationales and origins for key parts of the concept design, including use patterns, the relationship to Object-Oriented Programming, value arguments, notation, concept type-matching, and definition checking.

Keywords

Cite

@article{arxiv.2510.08969,
  title  = {Concept-Based Generic Programming in C++},
  author = {Bjarne Stroustrup},
  journal= {arXiv preprint arXiv:2510.08969},
  year   = {2025}
}