On this page
  1. Concepts (C++20)
  2. Overview
  3. Notes & Pitfalls
  4. Example

Concepts (C++20)

Prev: Move Semantics | Up: builtins | Next: Classes, Inheritance & virtual
Rel: Templates, Templates, Concepts & Polymorphism
Ref: cppreference — Constraints and Concepts
Tags: #public #prog #cpp #builtins #generics #tier/standard


Overview

Concepts (C++20) are named compile-time predicates that constrain template parameters. They replace SFINAE / std::enable_if boilerplate and turn multi-page template instantiation errors into short, readable constraint failures.

Notes & Pitfalls

Example

#include <cassert>
#include <concepts>

template <std::integral T>
T double_val(T x) { return x * 2; }

int main() {
    assert(double_val(21) == 42);
    // double_val(3.14); // clear compile-time concept error
}

Linked from

Related notes