16.10. Guard Operator

The binary guard operator is represented by the double colon ::. The guard expression is a generator expression and yields the value of the left operand only if the right operand (the guard) evaluates to true.

Guard Expression
[53]GuardExpression::=LogicalOrExpression { '::' LogicalOrExpression }  

The type of the guard expression is the type of the left operand. The type of the right operand must be boolean, or a compile-time error occurs.

The sequential evaluation of a guard expression evaluates both operands from left to right. If the result of the evaluation of the right operand is true, the result of the evaluation of the left operand is yielded as result. Then the sequential evaluation completes.