Concepts: How C++ Finally Got Compile-Time Constraints on Templates

Bjarne Stroustrup explains what C++ concepts are, why they are real and shippable today, and why it took decades to get them right.

BSBjarne StroustrupGuest
Channel
Lex Fridman Podcast
Video
10:24
Read
4 min
Original
English
Open on YouTube
Scroll to read and the video shrinks to the bottom-right corner. Captions follow your reading language.
Reading languageAvailable in 1 languages
You're reading the original English.
SUMMARY

In 30 seconds

Stroustrup describes concepts as compile-time predicates that state what a generic component requires of its parameters, such as what it means for something to be sortable. He says he wanted templates to be flexible, as fast as hand-written code and properly type-checked, and that earlier attempts at concepts failed because they did not fit C++ or its performance demands.

  1. 1Stroustrup says concepts are compile-time predicates that ask a type whether it has the properties a generic component needs, such as a begin and end, random access and a less-than operator.
  2. 2Concepts are not science fiction: working versions have existed for four or five years, they are part of C++20 and its standard library, and major compilers support them.
  3. 3The term comes from Alexander Stepanov, the father of generic programming, who called them concepts because they are the fundamental concepts of an area.
  4. 4Stroustrup wanted templates to be flexible, as fast as hand-written code, and properly type-checked, and for decades he and others did not know how to get all three at once.
  5. 5The earlier attempt around 2003 stumbled because it did not handle implicit conversions and mixed-type arithmetic well, compiled slowly, and could not meet C++'s performance requirements without optimizers beyond the state of the art.
TRANSCRIPT

Read the full transcript by chapter

01

Concepts are compile-time predicates, and you can use them today

Stroustrup starts by stressing that concepts are real: they did not exist ten years ago, but versions that work have been around for four or five years. The design came from Gabriel Dos Reis and himself, who were professors and postdocs in Texas at the time. It is part of C++20 along with the standard library components that use it, and it is available in clang and GCC, with Microsoft expected to follow as C++20 arrives in all major compilers.

He explains the basic idea with a sort function. Sorting needs at least two parameters: a data structure with a given type and a comparison criterion, and the two are related, since you can't compare things without knowing their type. To say something is sortable, you look up the standard's definition: it has to be a sequence with a beginning and an end, offer random access, and have element types that can be compared.

Concepts, he says, are compile-time predicates that ask exactly those questions. Are you a sequence, with a begin and an end? Are you a random-access sequence, with subscripting and addition? Does your element type have a less-than? Instead of accepting a parameter of any type, the function says it takes something sortable. The comparison criterion can be less-than, greater-than or something you invent, and it is written to operate on the element type.

02

The word comes from Stepanov, and C already had the idea informally

Stroustrup notes that the word concept was used by Alexander Stepanov, whom he calls the father of generic programming in the context of C++. Stepanov called them concepts because they are the fundamental concepts of an area, and so they should carry that name.

The idea itself has always existed, he argues. If you look at the K&R book on C, it describes arithmetic types and integral types, lists what they are and states their properties. What is new in C++ is that you can write a concept that asks a type whether it has the properties necessary to be integral, for instance whether it supports operations like multiply and divide.

03

Getting flexibility, speed and type checking together took decades

Lex Fridman asks why concepts did not arrive in C++11 and what made the idea so hard, going back to templates in the late 1980s. Stroustrup says he wanted three things from templates. They had to be flexible enough to express things he could not imagine, because he disliked languages that force you into only what the designer thought good. They also had to run as fast as or faster than hand-written code, and to have proper type checking of interfaces.

Neither he nor anyone else knew how to get all three, and he thought C++ must have the first two or it would not be C++. It bothered him for a couple of decades, especially since he had put function argument type checking into C and valued good interfaces. A renewed attempt came around 2003, when he and Dos Reis analyzed the problem and possible solutions, and a group at Indiana University began a project.

They thought a good system could be done in a couple of years and make it into C++11, but he now thinks many of the fundamental ideas were wrong. They were unconventional for C++, handled implicit conversions and mixed-type arithmetic poorly, and drew heavily from the functional community, which treats multiple types differently and lacks C++'s draconian performance requirements.

In the end, he says, it was too slow to compile, too hard to use, and did not run fast enough without optimizers beyond the state of the art. The approach treated a set of parameters as defining a set of operations reached through an indirection table, like virtual functions, and relied on optimizing that indirection away. They could not make that work, so they had to do something else.

More from this channel

3:36:56EN
Lex Fridman· Sep 16, 2026PodcastPsychiatry Has Never Found Its PenicillinHost Lex FridmanHistorian Andrew Scull tells Lex Fridman why the field can ease symptoms, has never cured a major mental illness, and keeps paying for overconfidence with patients' lives.Mental HealthPublic HealthNeuroscience
5:15:51EN
Lex Fridman· Aug 26, 2026Podcast · 2 speakersDHH Did Not Write a Line of Omarchy QuattroGuest DHH · Host Lex FridmanThirteen months after a skeptical conversation with Lex Fridman, the Rails creator describes how Opus 4.5, a swarm of coding agents, and a one-minute Linux installer ended his era of hand-chiseled Ruby.Coding agentsVibe CodingAgent engineering+3
3:12:58EN
Lex Fridman· Aug 12, 2026Podcast · 2 speakersOne Cold Shower, Twenty Champions: How Khabib Nurmagomedov Was ForgedGuest Khabib Nurmagomedov · Host Lex FridmanIn a Makhachkala school gym, seventy men shared one shower, and the water was only cold.Martial ArtsCombat SportsCoaching+3
3:46:18EN
Lex Fridman· Jul 28, 2026Podcast · 2 speakersIf You Take Slavery Out of the Picture, There Is No Civil WarGuest Gary Gallagher · Host Lex FridmanIn 1860, enslaved people were worth more than every railroad and factory in the United States combined.Political PhilosophyLeadershipHistory
3:51:47EN
Lex Fridman· Jun 30, 2026Podcast · 2 speakersForty-Six Percent of Emperors Were Overthrown. The Empire Lasted AnywayGuest Anthony Kaldellis · Host Lex FridmanHistorian Anthony Kaldellis walks Lex Fridman through 2,200 years of Roman history and argues that what we call Byzantium was Rome itself.Political PhilosophyGeopoliticsLeadership
2:53:42EN
Lex Fridman· May 29, 2026Podcast · 2 speakersThe Moon Is Falling. It Just Keeps Missing.Guest Biggest Mysteries in Physics · Host Lex FridmanFermilab physicist Don Lincoln tells Lex Fridman that the history of physics is a history of unification, and that antimatter, dark energy, and a theory of everything still sit far beyond the experiments we can run.Quantum MechanicsScience CommunicationPhilosophy of Science