From questions like this, from C++20 - The Complete Guide, and even from cppreference, my understanding is that the keyword requires can do one of 2 things only:
- introduce a requires-clause
- introduce a requires-expression
and I also think I've understand more or less what they are for, thanks to linked sources.
However, I'm puzzled by the use of requires inside a requires-expression, e.g.
template<typename T>
… requires {
requires std::is_const_v<T>;
}
From the standard draft, I read that a requires-expression (e.g. the one introduced by the first requires in the snippet above) must have a requirement-body, which must in turn be a { requirement-seq }, i.e. something between curly braces, which is not the case of std::is_const_v<T>;, from which I deduce that requires std::is_const_v<T>; is a requires-clause, that should look like this
requiresconstraint-logical-or-expression
However, [expr.prim.req.nested] tells me that a nested-requirement looks like this:
requiresconstraint-expression;
So maybe use of requires nested in a requires-expression is not a requires-clause?
If it is, I think the difference between the two quoted grammars above should mean that nested-requirements are a subset of requires-clauses, in which case I should be able to see, following the various cross-references, that a constraint-expression is a constraint-logical-or-expression but not viceversa. Now I see that
- a constraint-logical-or-expression can be a primary-expression,
- which can be in turn an
( expression ) - expression (unparenthesized) can be an assignment-expression
- which can be a conditional-expression
- which can be a logical-or-expression
And a constraint-expression is a logical-expression too.
But what I don't understand is where the parenthesis are gone.