Introduction
The concept behind C++ concepts
The motivation behind concepts
Quiz 1
1 attempt allowed
Exercise 1
4 ways to use concepts in functions
The 4 ways to use concepts
The requires clause
The trailing requires clause
The constrained template parameter
Abbreviated function templates
Quiz 2
1 attempt allowed
Exercise 2
Choosing among the 4 forms
They are all compiled the same way
How to choose among the 4 ways?
Quiz 3
1 attempt allowed
Exercise 3
C++ concepts with classes
The requires clause
Constrained template parameters
Quiz 4
1 attempt allowed
Constraining member functions with concepts
The trailing requires clause
Quiz 5
1 attempt allowed
Exercise 4
Standard concepts in
std::convertible_to for conversions with fewer surprises
std::totally_ordered for defined comparisons
std::copyable for copyable types
Quiz 6
1 attempt allowed
Standard concepts in
and Concepts in the
header std::indirect_unary_predicate
std::indirectly_comparable
Concepts in the
header Quiz 7
1 attempt allowed
Combining and negating concepts
The simplest concept
Use already defined concepts
!a is not the opposite of a
Negations come with parentheses
Subsumption and negations
Quiz 8
1 attempt allowed
Exercise 5
Requirements on operations and interfaces
Requirements on operations
Simple requirements on the interface
Quiz 9
1 attempt allowed
Exercise 6
Compound and type requirements
Requirements on return types (a.k.a compound requirements)
Type requirements
Require the existence of a nested type
A class template specialization should name a type
An alias template specialization should name a type
Quiz 10
1 attempt allowed
Exercise 7
Nested requirements
Quiz 11
1 attempt allowed
Exercise 8
Real-life concepts: numbers and utilities
Numbers finally
Utility functions constrained
Quiz 12
1 attempt allowed
Exercise 9
Multiple destructors with concepts
The need for multiple destructors
Multiple destructors before C++20
Multiple destructors with C++20
Quiz 13
1 attempt allowed
Exercise 10
Summary
Quiz 14
2 attempts allowed
C++20 Concepts: Validate Your Templates at Compile-Time
Write Safer Templates with Less Boilerplate
Stop wrestling with SFINAE and enable_if. C++20 concepts let you constrain templates with readable, compile-time predicates - no runtime cost, no cryptic error messages. This course takes you from understanding why concepts exist to writing your own production-ready constraints, with quizzes and exercises at every step.
Minimum price
$19.00
$24.00
You pay
Author earns
About
About the Course
Templates are powerful but permissive. Without constraints, they accept types the author never intended - and when they fail, the error messages are walls of text that point to the wrong place. Before C++20, the workarounds were static_assert, enable_if, and SFINAE: verbose, fragile, and difficult to read.
Concepts change this. They let you express what a template expects directly in its signature, checked at the point of call, with clear error messages and zero runtime overhead.
This course teaches you how to use and write C++ concepts through 15 focused lessons, each with quizzes and hands-on exercises. You'll learn the four syntax forms for functions, how to constrain class templates and individual member functions, what the standard library ships out of the box, and how to write your own concepts - from simple boolean combinations to compound requirements, type requirements, and nested requirements. The final lessons apply everything to real-world problems: a complete number concept, self-documenting utility functions, and multiple destructors for optimization.
By the end, you'll be able to read, write, and apply concepts in your own codebase. No SFINAE experience required — just basic template knowledge.
Categories
Instructor
About the Instructor
I am a C++ software craftsman with strong Python working in the tourism and hospitality industry and an enthusiastic blogger writing about coding, books, and the importance of stoic philosophy in a software developer's life.
I moved to software development from database operations which means that I don't just care about delivering a product as fast as possible, but I do understand the importance of stability and maintainability.
I'm passionate about delivering clean solutions, but I find even more important to help my teams to constantly raise the bar and to (re)focus on quality and clean code. I do this by explaining how high-quality work will help them in their individual careers, by introducing more meaningful development processes and automation and by teaching them industry best practices.
Material
Course Material
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.