Init
This commit is contained in:
124
cppdraft/expr/rel.md
Normal file
124
cppdraft/expr/rel.md
Normal file
@@ -0,0 +1,124 @@
|
||||
[expr.rel]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.6 Compound expressions [[expr.compound]](expr.compound#expr.rel)
|
||||
|
||||
### 7.6.9 Relational operators [expr.rel]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7404)
|
||||
|
||||
The relational operators group left-to-right[.](#1.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
a<b<c means (a<b)<c and not(a<b)&&(b<c)[.](#1.sentence-2)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[relational-expression:](#nt:relational-expression "7.6.9 Relational operators [expr.rel]")
|
||||
[*compare-expression*](expr.spaceship#nt:compare-expression "7.6.8 Three-way comparison operator [expr.spaceship]")
|
||||
[*relational-expression*](#nt:relational-expression "7.6.9 Relational operators [expr.rel]") < [*compare-expression*](expr.spaceship#nt:compare-expression "7.6.8 Three-way comparison operator [expr.spaceship]")
|
||||
[*relational-expression*](#nt:relational-expression "7.6.9 Relational operators [expr.rel]") > [*compare-expression*](expr.spaceship#nt:compare-expression "7.6.8 Three-way comparison operator [expr.spaceship]")
|
||||
[*relational-expression*](#nt:relational-expression "7.6.9 Relational operators [expr.rel]") <= [*compare-expression*](expr.spaceship#nt:compare-expression "7.6.8 Three-way comparison operator [expr.spaceship]")
|
||||
[*relational-expression*](#nt:relational-expression "7.6.9 Relational operators [expr.rel]") >= [*compare-expression*](expr.spaceship#nt:compare-expression "7.6.8 Three-way comparison operator [expr.spaceship]")
|
||||
|
||||
The
|
||||
lvalue-to-rvalue ([[conv.lval]](conv.lval "7.3.2 Lvalue-to-rvalue conversion"))
|
||||
and function-to-pointer ([[conv.func]](conv.func "7.3.4 Function-to-pointer conversion"))
|
||||
standard conversions are performed on the operands[.](#1.sentence-3)
|
||||
|
||||
If one of the operands is a pointer, the
|
||||
array-to-pointer conversion ([[conv.array]](conv.array "7.3.3 Array-to-pointer conversion")) is performed on the other operand[.](#1.sentence-4)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7435)
|
||||
|
||||
The converted operands shall have arithmetic, enumeration, or pointer type[.](#2.sentence-1)
|
||||
|
||||
The
|
||||
operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) all
|
||||
yield false or true[.](#2.sentence-2)
|
||||
|
||||
The type of the result isbool[.](#2.sentence-3)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7443)
|
||||
|
||||
The usual arithmetic conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions")) are performed on operands of arithmetic
|
||||
or enumeration type[.](#3.sentence-1)
|
||||
|
||||
If both converted operands are pointers,
|
||||
pointer conversions ([[conv.ptr]](conv.ptr "7.3.12 Pointer conversions")),
|
||||
function pointer conversions ([[conv.fctptr]](conv.fctptr "7.3.14 Function pointer conversions")), and
|
||||
qualification conversions ([[conv.qual]](conv.qual "7.3.6 Qualification conversions"))
|
||||
are performed to bring
|
||||
them to their [composite pointer type](expr.type#def:composite_pointer_type "7.2.2 Type [expr.type]")[.](#3.sentence-2)
|
||||
|
||||
After conversions, the operands shall have the same type[.](#3.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7453)
|
||||
|
||||
The result of comparing unequal pointers to objects[65](#footnote-65 "As specified in [basic.compound], an object that is not an array element is considered to belong to a single-element array for this purpose and a pointer past the last element of an array of n elements is considered to be equivalent to a pointer to a hypothetical array element n for this purpose.") is defined in terms of a partial order consistent with the following rules:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
If two pointers point to different elements of the same array, or to
|
||||
subobjects thereof, the pointer to the element with the higher subscript
|
||||
is required to compare greater[.](#4.1.sentence-1)
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
If two pointers point to different non-static data members of the same
|
||||
object, or to subobjects of such members, recursively,
|
||||
the pointer to the later declared member is required to compare greater provided
|
||||
neither member is a subobject of zero size
|
||||
and their class is not a union[.](#4.2.sentence-1)
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
Otherwise, neither pointer is required to compare greater than the other[.](#4.3.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7479)
|
||||
|
||||
If two operands p and q compare equal ([[expr.eq]](expr.eq "7.6.10 Equality operators")),p<=q and p>=q both yield true and p<q andp>q both yield false[.](#5.sentence-1)
|
||||
|
||||
Otherwise, if a pointer to object p compares 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[.](#5.sentence-2)
|
||||
|
||||
Otherwise, the result of each of the operators is unspecified[.](#5.sentence-3)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
A relational operator applied
|
||||
to unequal function pointers
|
||||
yields an unspecified result[.](#5.sentence-4)
|
||||
|
||||
A pointer value of type âpointer to cv voidâ
|
||||
can point to an object ([[basic.compound]](basic.compound "6.9.4 Compound types"))[.](#5.sentence-5)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L7495)
|
||||
|
||||
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[.](#6.sentence-1)
|
||||
|
||||
[65)](#footnote-65)[65)](#footnoteref-65)
|
||||
|
||||
As specified in [[basic.compound]](basic.compound "6.9.4 Compound types"),
|
||||
an object that is not an array element
|
||||
is considered to belong to a
|
||||
single-element array for this purpose and
|
||||
a pointer past the last element of an array of n elements
|
||||
is considered to be equivalent to a pointer to a hypothetical array elementn for this purpose[.](#footnote-65.sentence-1)
|
||||
Reference in New Issue
Block a user