@@ -503,7 +503,7 @@ $(GNAME CmpExpression):
503
503
$(GLINK ShiftExpression)
504
504
)
505
505
506
- $(H2 $(LNAME2 equality_expressions, Equality Expressions))
506
+ $(H3 $(LNAME2 equality_expressions, Equality Expressions))
507
507
508
508
$(GRAMMAR
509
509
$(GNAME EqualExpression):
@@ -530,7 +530,7 @@ $(GNAME EqualExpression):
530
530
$(P For float, double, and real values, the $(USUAL_ARITHMETIC_CONVERSIONS) are applied
531
531
to bring them to a common type before comparison.
532
532
The values $(D -0) and $(D +0) are considered equal.
533
- If either or both operands are NAN , then $(D ==) returns false and $(D !=) returns $(D true).
533
+ If either or both operands are NaN , then $(D ==) returns false and $(D !=) returns $(D true).
534
534
Otherwise, the bit patterns of the common type are compared for equality.
535
535
)
536
536
@@ -545,7 +545,7 @@ $(GNAME EqualExpression):
545
545
x.re == y.re && x.im == y.im
546
546
---
547
547
548
- $(H3 $(LNAME2 class_struct_equality, Class & Struct Equality))
548
+ $(H4 $(LNAME2 class_struct_equality, Class & Struct Equality))
549
549
550
550
$(P For struct objects, equality means the result of the
551
551
$(LINK2 https://dlang.org/spec/operatoroverloading.html#equals, `opEquals()` member function).
@@ -579,7 +579,7 @@ $(GNAME EqualExpression):
579
579
operators are intended to compare the contents of the objects,
580
580
however an appropriate $(D opEquals) override must be defined for this to work.
581
581
The default $(D opEquals) provided by the root $(D Object) class is
582
- equivalent to the $(D is) operator.
582
+ equivalent to the $(D is) operator (see below) .
583
583
Comparing against $(D null) is invalid, as $(D null) has no contents.
584
584
Use the $(D is) and $(D !is) operators instead.)
585
585
@@ -621,14 +621,28 @@ $(GNAME IdentityExpression):
621
621
of elements.
622
622
)
623
623
624
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
625
+ ---
626
+ Object o;
627
+ assert(o is null);
628
+
629
+ auto a = [1, 2];
630
+ assert(a is a[0..$]);
631
+ assert(a !is a[0..1]);
632
+
633
+ auto b = [1, 2];
634
+ assert(a !is b);
635
+ ---
636
+ )
637
+
624
638
$(P For other operand types, identity is defined as being the same
625
639
as equality.
626
640
)
627
641
628
642
$(P The identity operator $(D is) cannot be overloaded.
629
643
)
630
644
631
- $(H2 $(LNAME2 relation_expressions, Relational Expressions))
645
+ $(H3 $(LNAME2 relation_expressions, Relational Expressions))
632
646
633
647
$(GRAMMAR
634
648
$(GNAME RelExpression):
@@ -642,16 +656,16 @@ $(GNAME RelExpression):
642
656
The result type of a relational expression is $(D bool).
643
657
)
644
658
645
- $(H3 $(LNAME2 array_comparisons, Array comparisons ))
659
+ $(H3 $(LNAME2 array_comparisons, Array Comparisons ))
646
660
647
- $(P For static and dynamic arrays, the result of the relational
648
- op is the result of the operator applied to the first non-equal
661
+ $(P For static and dynamic arrays, the result of a *CmpExpression*
662
+ is the result of the operator applied to the first non-equal
649
663
element of the array. If two arrays compare equal, but are of
650
664
different lengths, the shorter array compares as "less" than the
651
665
longer array.
652
666
)
653
667
654
- $(H3 $(LNAME2 integer_comparisons, Integer comparisons ))
668
+ $(H3 $(LNAME2 integer_comparisons, Integer Comparisons ))
655
669
656
670
$(P Integer comparisons happen when both operands are integral
657
671
types.
@@ -673,13 +687,13 @@ $(H3 $(LNAME2 integer_comparisons, Integer comparisons))
673
687
Use casts to make both operands signed or both operands unsigned.
674
688
)
675
689
676
- $(H3 $(LEGACY_LNAME2 floating_point_comparisons, floating-point-comparisons, Floating point comparisons ))
690
+ $(H3 $(LEGACY_LNAME2 floating_point_comparisons, floating-point-comparisons, Floating Point Comparisons ))
677
691
678
692
$(P If one or both operands are floating point, then a floating
679
693
point comparison is performed.
680
694
)
681
695
682
- $(P A relational operator can have `NaN` operands.
696
+ $(P A *CmpExpression* can have `NaN` operands.
683
697
If either or both operands is `NaN`, the floating point
684
698
comparison operation returns as follows:)
685
699
@@ -693,11 +707,14 @@ $(H3 $(LEGACY_LNAME2 floating_point_comparisons, floating-point-comparisons, Flo
693
707
$(TROW $(D !=),$(ARGS unordered, less, or greater), `true`)
694
708
)
695
709
696
- $(H3 $(LEGACY_LNAME2 class_comparisons, class-comparisons, Class comparisons))
710
+ $(BEST_PRACTICE Although *IdentityExpression* can be used to check for `T.nan`,
711
+ there are other floating-point values for NaN produced at runtime.
712
+ Use $(REF isNaN, std,math,traits) to handle all of them.)
697
713
698
- $(P For class objects, the relational
699
- operators compare the
700
- contents of the objects. Therefore, comparing against
714
+ $(H3 $(LEGACY_LNAME2 class_comparisons, class-comparisons, Class Comparisons))
715
+
716
+ $(P For class objects, *EqualExpression* and *RelExpression* compare the
717
+ *contents* of the objects. Therefore, comparing against
701
718
a $(CODE null) class reference is invalid, as $(CODE null) has no contents.)
702
719
703
720
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
@@ -711,13 +728,14 @@ $(H3 $(LEGACY_LNAME2 class_comparisons, class-comparisons, Class comparisons))
711
728
)
712
729
713
730
$(P For class objects, the result of `Object.opCmp()` forms the left
714
- operand, and `0` forms the right operand. The result of the
715
- relational expression `(o1 op o2)` is:)
731
+ operand, and `0` forms the right operand. The result of an
732
+ *EqualExpression* or *RelExpression* `(o1 op o2)` is:)
716
733
717
734
---
718
735
(o1.opCmp(o2) op 0)
719
736
---
720
737
738
+
721
739
$(H2 $(LNAME2 in_expressions, In Expressions))
722
740
723
741
$(GRAMMAR
0 commit comments