The <requires> Clause
Get an overview of the <requires> clause.
We'll cover the following...
How to write aq requires
clause?
In the first way, we use the required
clause between the template parameter list and the function return type, which is auto
in this case.
Press + to interact
#include <concepts>template <typename T>concept Number = std::integral<T> || std::floating_point<T>;template <typename T>requires Number<T>auto add(T a, T b) {return a+b;}
Note how we use the concept and define our constraint in the requires
clause that any T
template parameter must satisfy the requirements of the concept Number
. In order to determine the return type we ...