Back to results for “Concepts & Constraints”
C++ › Concepts & Constraints

What are some standard library concepts?

Beginner

Answer

The standard library defines many concepts in <concepts> and elsewhere: std::integral, std::floating_point, std::same_as, std::convertible_to, std::equality_comparable, std::totally_ordered, std::copyable, std::movable, std::invocable, and range/iterator concepts. They cover common type requirements so you rarely need to write your own.
template <std::floating_point T> T half(T x){ return x/2; }
Real-world example Constraining math helpers with std::floating_point documents and enforces that only real-number types are accepted.

Common follow-ups: Where are standard concepts defined? | Name a few common ones.