Files
2025-10-25 03:02:53 +03:00

4.1 KiB
Raw Permalink Blame History

[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

1

#

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:

  • (1.1)

    Substitution of template arguments (if any) into the expression is performed.

  • (1.2)

    If the noexcept specifier is present,E shall not be a potentially-throwing expression ([except.spec]).

  • (1.3)

    If the return-type-requirement is present, then:

    [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]

2

#

[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]