what is a requires requires constraint?

Not sure if I understand the use of requires requires as in this code:


1
2
3
template<typename T>
requires requires (T x) { x + x; } // ad-hoc constraint, note keyword used twice
T add(T a, T b) { return a + b; }



the requires expression
 
requires (T x) { x + x; }



is an unnamed concept right?

So this syntax allows us to write a concept "inline" without placing a name to it. Right? Is this the purpose of the requires requires constraint?


Regards,
Juan
The requires expression is an unnamed concept right?
It's an expression of type bool.
requires (T x) { x + x; }
Can be read as "For an object of type T named x, the constraint x + x is satisfied?"

In the requires-clause
1
2
3
template<typename T>
requires constraint
T add(T a, T b) { return a + b; }

constraint is some constant expression which says whether the constraints are satisfied. The predicate
requires (T x) { x + x; }
is that constant expression.
Topic archived. No new replies allowed.