<concepts> provides standard concepts (type constraints) introduced in C++20: std::integral, std::floating_point, std::regular, std::equality_comparable, etc. A concept is a compile-time predicate on types that lets you write generic code with enforced requirements.
Use concepts to constrain template parameters so that invalid instantiations fail with clear error messages rather than cryptic SFINAE errors deep in the template.
This example constrains a template function to accept only integral types, preventing accidental instantiation with floating-point arguments.
// compile: g++ -std=c++20 -o conceptexample conceptexample.cpp // run: ./conceptexample // description: template function constrained by std::integral concept #include <concepts> #include <iostream> template <std::integral T> T double_value(T x) { return x * 2; } int main() { std::cout << "double_value(5): " << double_value(5) << "\n"; std::cout << "double_value(3u): " << double_value(3u) << "\n"; // double_value(3.14); // error: double does not satisfy std::integral return 0; }