[expr.rel] (original) (raw)

7 Expressions [expr]

7.6 Compound expressions [expr.compound]

7.6.9 Relational operators [expr.rel]

The relational operators group left-to-right.

[Example 1:

a<b<c means (a<b)<c and not (a<b)&&(b<c).

— _end example_]

The lvalue-to-rvalue ([conv.lval]) and function-to-pointer ([conv.func]) standard conversions are performed on the operands.

If one of the operands is a pointer, the array-to-pointer conversion ([conv.array]) is performed on the other operand.

The converted operands shall have arithmetic, enumeration, or pointer type.

The operators < (less than), > (greater than), <=(less than or equal to), and >= (greater than or equal to) all yield false or true.

The type of the result isbool.

The usual arithmetic conversions ([expr.arith.conv]) are performed on operands of arithmetic or enumeration type.

After conversions, the operands shall have the same type.

The result of comparing unequal pointers to objects65is defined in terms of a partial order consistent with the following rules:

If two operands p and q compare equal ([expr.eq]),p<=q and p>=q both yield true and p<q andp>q both yield false.

Otherwise, if a pointer to object pcompares greater than a pointer q, p>=q, p>q,q<=p, and q<p all yield true and p<=q,p<q, q>=p, and q>p all yield false.

Otherwise, the result of each of the operators is unspecified.

[Note 1:

A relational operator applied to unequal function pointers yields an unspecified result.

A pointer value of type “pointer to cv void” can point to an object ([basic.compound]).

— _end note_]

If both operands (after conversions) are of arithmetic or enumeration type, each of the operators shall yield true if the specified relationship is true and false if it is false.