0Pricing
C++ Academy · Lesson

Defining Concepts with requires

Define custom concepts using requires expressions and constraints.

The concept Keyword

Declare a concept with template <params> concept Name = expression; The expression must be a compile-time boolean.

template <typename T>
concept Integer = std::is_integral_v<T>;

Combining Type Traits

Use logical operators to combine traits into a concept.

template <typename T>
concept SignedInteger = std::is_integral_v<T> && std::is_signed_v<T>;

All lessons in this course

  1. Why Concepts vs SFINAE
  2. Defining Concepts with requires
  3. Using Concepts in Templates and auto
  4. Common Standard Concepts Integral Ranges
← Back to C++ Academy