Skip to content

C++20 Concepts (EN)

A short historical overview about the development of the
programming language and the implementation of “Templates” and “Concepts.”

by Michael Hava, MSc

The famous Bjarne Stroustrup, the inventor of the programming language C++, which is still widely used today, originally started developing C with Classes in 1979 at Bell Labs. His goal was a programming language that would combine the speed of C with the organizational capabilities (=object orientation) of Simula which were and still are necessary for large projects.

Table of contents

  • Algorithms are defined on algebraic structures
  • No completion of Templates in sight
  • First Concepts-based library
  • Author
Prorgamming

Due to the great success, Stroustrup began barely ten years later (1987) to work on an extension of the language, which in the meantime had been renamed C++: Templates – this generic concept was intended to enable the implementation of generic classes and functions, and thus incidentally to largely replace the pre-processor macros taken over from C. The development of these Templates was based essentially on three Design goals:

  • full generality: templates should not be targeted at individual use cases, but should be designed for broad use.
  • zero overhead: Code generated by templates should be indistinguishable from handwritten code (in terms of efficiency, performance, etc.) after compilation.
  • good interfaces (“constraints”): Similarly as C++ had improved the type security in relation to C, generic interfaces are to represent an improvement, too.

Result of the work: It seems to be impossible to achieve all three goals at the same time at the current state of research. Since the first two goals are essential for the acceptance of templates, while constraints “only” improve usability, templates are added to C++ without them. Constraints are to be added as soon as possible.

C++ Logo

Algorithms are defined on algebraic structures

In the year 1994, C++ (now on its way to becoming an ISO standard) is extended by the Standard Template Library (STL), a library for generic algorithms and container classes. It is the result of Alexander Stepanov‘s nearly 20 years of research on generic programming and is fundamentally different from contemporary object-oriented approaches.

At the beginning of this research his realization stood firm in 1976: algorithms are defined on algebraic structures. Based on the mathematical model of algebraic structures, he developed Concepts [1], the central pillar of generic programming. Analogous to algebraic structures, concepts describe the required operations and underlying mathematical axioms, which an algorithm places on the data to be processed. The goal of generic programming is to define algorithms based only on the minimum necessary concepts and thus make them usable for a variety of concrete types.

After experiments in several programming languages (Scheme, Ada, …) C++ is the first, which is expressive enough for generic programming Alexander Stepanov thought – even if the missing support for concepts makes complex emulations necessary. With the integration of the STL into the standard library, the idea of Concepts is also taken over in C++. From a programming language perspective, concepts are a formal representation of constraints. The focus for the completion of templates shifts subsequently to Concepts. Nevertheless, the first C++ ISO standard 1998 (C++98) appears without extensions of the template system, Concepts must be emulated further.

Computer Head

No completion of Templates in sight

In the first years after C++98, the standard committee focused on bug fixing and stabilization. Therefore, the development of Concepts did not pick up again until 2003 as part of the work on the next C++ standard (C++0x). Bjarne Stroustrup and Gabriel Dos Reis published a series of papers on a possible Concepts design. A research group at Indiana University also published their results in 2005. The two contrasting approaches gave rise to the joint C++0x Concepts design in 2006, which was incorporated into the working draft of the C++ standard in 2008.

In the months that followed, however, some problems with the design became apparent. Since the completion of the new standard was already postponed several times and it can be assumed that the bug fixing will lead to further postponements, the standard committee removed Concepts from the working draft again in 2009. C++11 thus appeared 13 years after the first standard still without the completion of templates.

Progamming

First Concepts-based library

While working on C++14, Bjarne Stroustrup, Gabriel Dos Reis and Andrew Sutton designed a new draft – Concepts Lite – based on the findings of C++0x Concepts in 2013. The key difference to the old approach: This time they focus on a “minimal feature” [2], which can be extended later if needed. The result of their work is published in 2015 as a Technical Specification (TS) [3].

In summer 2017, four months after the completion of C++17, concepts based on the TS are integrated into the working draft for C++20. Together with the language extension, a library extension of pre-built basic Concepts is provided. This will be followed in 2018 by Ranges, the first Concepts-based library – it contains, among other things, the STL algorithms verified with Concepts. C++20 will be adopted in February 2020 and unanimously approved in September 2020.

Footnotes

[1] The implicit counterpart of generic programming to the explicit interfaces from object-oriented programming.

[2] For example, language resources on axioms and definition checks are missing, among other things.

[3] Independent ISO document that contains possible extensions for a standard. The goal is to get user feedback and to include a version of the content in an ISO standard.

Contact









    Author

    Michael Hava, MSc

    Senior Software Architect