4.1 KiB
[expr.prim.req.compound]
7 Expressions [expr]
7.5 Primary expressions [expr.prim]
7.5.8 Requires expressions [expr.prim.req]
7.5.8.4 Compound requirements [expr.prim.req.compound]
compound-requirement:
{ expression } noexceptopt return-type-requirementopt ;
return-type-requirement:
-> type-constraint
A compound-requirement asserts properties of the expression E.
The expression is an unevaluated operand.
Substitution of template arguments (if any) and verification of semantic properties proceed in the following order:
-
Substitution of template arguments (if any) into the expression is performed.
-
If the noexcept specifier is present,E shall not be a potentially-throwing expression ([except.spec]).
-
If the return-type-requirement is present, then:
-
Substitution of template arguments (if any) into the return-type-requirement is performed.
-
The immediately-declared constraint ([temp.param]) of the type-constraint for decltype((E)) shall be satisfied.
[Example 1: Given concepts C and D,requires {{ E1 } -> C; { E2 } -> D<A1, â¯, An>;}; is equivalent torequires { E1; requires C<decltype((E1))>; E2; requires D<decltype((E2)), A1, â¯, An>;}; (including in the case where n is zero). â end example]
-
[Example 2: template concept C1 = requires(T x) {{x++};};
The compound-requirement in C1 requires that x++ is a valid expression.
It is equivalent to the simple-requirementx++;.
template concept C2 = requires(T x) {{*x} -> std::same_as;};
The compound-requirement in C2 requires that *x is a valid expression, that typename T::inner is a valid type, and that std::same_as<decltype((*x)), typename T::inner> is satisfied.
template concept C3 =requires(T x) {{g(x)} noexcept; };
The compound-requirement in C3 requires that g(x) is a valid expression and that g(x) is non-throwing.
â end example]