Concepts — named constraints on template parameters.
1template <typename T>2concept Numeric = std::is_arithmetic_v<T>;34template <Numeric T>5T add(T a, T b) { return a + b; }67// Constrained auto8auto result = add(3, 4); // OK9// add("a", "b"); // Error: not Numeric
Concepts with requires:
1template <typename T>2concept Container = requires(T t) {3 std::begin(t);4 std::end(t);5 t.size();6};78void print(Container auto const& c) {9 for (const auto& elem : c) { /* ... */ }10}
Benefits: