Generic Programming in ConceptC++

ConceptC++ is an extension to the C++ Programming Language that introduces first-class support for Generic Programming. It is the first attempt to introduce complete support for Generic Programming into a mainstream programming language. ConceptC++ is a strong candidate for inclusion into the upcoming ANSI/ISO C++ Standard, dubbed C++0x. The Open Systems Laboratory at Indiana University is developing a prototype compiler for ConceptC++, ConceptGCC.

ConceptC++ boasts many features that directly support Generic Programming. The major features are:

  • Concepts: Concepts are sets of requirements bundled together under a single name. There are several types of requirements, but the most common kinds are (1) functions, constructors, and operators that the data types must have and (2) associated types that are typically used to express those functions, constructors, and operators. ConceptC++ concepts can directly express refinement relationships, nested requirements, etc., so that all important syntactic features of concepts can be encoded directly in ConceptC++.
  • Concept maps: Concept maps state how a set of types meets the requirements of a concept, and are ConceptC++'s implementation of models. They are the "glue" that makes it possible to map from whatever syntax the user types use to the syntax required by the algorithms that use those concepts, giving ConceptC++ complete support for retroactive modeling. This glue makes templates more reusable, because you don't have to change your types to use them with a generic algorithm, even if the algorithm uses a completely different syntax!
  • Requirements clauses: Requirements clauses state the requirements that are placed on a template. The user must be sure to meet all of those requirements are met when using the template, but also the author of the template may only use what has been required: thus, ConceptC++ gives complete type-checking of templates at definition time. This means that errors in the definition of templates will be caught at definition time, so they won't slip through to users of a library. It also means that when a template is misused (i.e., the requirements of the template, as expressed in the requirements clause, are not met), a ConceptC++ compiler can produce clean, concise error messages describing the problem.
  • Concept-based overloading: Crucial for performance, ConceptC++ fully supports both specialization based on concepts and concept-based overloading, by extending C++'s rules for specialization and partial ordering of function templates.
  • A concept-enabled Standard Library: Many of the algorithms in the ConceptC++ Standard Library use concepts in their descriptions. Although this change is mainly transparent to users--almost all code still works as it did before--mistakes that used to generate horribly long error messages now produce short, meaningful error messages. Moreover, users can enjoy the benefits of retroactive modeling with Standard Library algorithms.

Learning Concepts

There are many ways to learn about Concepts in C++. Here are just a few:

  • Concepts: Extending the C++ Template System for Generic Programming: an introductory Concepts talk given as a Google Tech Talk by Douglas Gregor in February, 2007.
  • ACCU 2007: Douglas Gregor will be giving a Concepts tutorial as part of the ACCU 2007 "Future of C++" track. Slides in [PowerPoint] [PDF].
  • BoostCon 2007: Douglas Gregor will be giving a hands-on Concepts tutorial and an advanced discussion on evolving generic libraries to use concepts at BoostCon 2007.
  • ConceptC++ Tutorial: A short tutorial in the use of concepts. Best when used with the ConceptGCC compiler.
  • Concepts: Linguistic Support for Generic Programming in C++: A paper published at OOPSLA 2006 describing the concepts system, its use in the C++ Standard Library, and its implementation.
  • ConceptC++ Specification: Links to the actual specification of concepts in C++. While these specifications generally have some introductory material, they are best consulted after one of the more introductory papers, talks, or tutorials.