C++20 Concepts

What advantage do C++20 concepts provide over SFINAE for constraining templates?

// SFINAE approach
template<typename T>
auto add(T a, T b) -> decltype(a + b) { return a + b; }

// Concepts approach
template<typename T>
requires requires(T a, T b) { a + b; }
T add(T a, T b) { return a + b; }
A

Concepts eliminate the need for templates entirely by using runtime polymorphism instead

B

Concepts are faster at runtime because constraints are checked dynamically

C

Concepts express the constraint directly and produce clear error messages when violated, instead of cryptic template substitution failures

D

Concepts allow templates to work with types that don't satisfy the constraint by providing a fallback