@@ -383,19 +383,20 @@ $(H2 $(LNAME2 eqcmp, Overloading the Comparison Operators))
383
383
$(D x < y) nor $(D y < x) holds, but that does not imply that
384
384
$(D x == y). Thus, it is insufficient to determine equality purely based on
385
385
$(D opCmp) alone. For this reason, $(D opCmp) is only used for the
386
- inequality operators $(D <), $(D <=), $(D >=), and $(D >). The equality
386
+ $(GLINK2 RelExpression) operators $(D <), $(D <=), $(D >=), and $(D >). The equality
387
387
operators $(D ==) and $(D !=) always employ $(D opEquals) instead.)
388
388
389
389
$(P Therefore, it is the programmer's responsibility to ensure that
390
390
`opCmp` and $(D opEquals) are consistent with each other. If
391
- `opEquals` is not specified, the compiler provides a default version
391
+ `opEquals` is not specified for a struct, the compiler provides a
392
+ $(DDSUBLINK spec/expression, struct_equality, default version) of it
392
393
that does member-wise comparison. If this suffices, one may define only
393
- $(D opCmp) to customize the behaviour of the inequality operators. But
394
+ $(D opCmp) to customize the behaviour of the *RelExpression* operators. But
394
395
if not, then a custom version of $(D opEquals) should be defined as
395
396
well, in order to preserve consistent semantics between the two kinds
396
397
of comparison operators.)
397
398
398
- $(P Finally, if the user-defined type is to be used as a key in the
399
+ $(P Finally, if a user-defined type is to be used as a key in the
399
400
built-in associative arrays, then the programmer must ensure that the
400
401
semantics of $(D opEquals) and $(D toHash) are consistent. If not, the
401
402
associative array may not work in the expected manner.)
@@ -562,13 +563,20 @@ struct S
562
563
int opCmp(ref const S s) const { ... }
563
564
}
564
565
---
565
- $(P Note that $(D opCmp) is only used for the inequality operators;
566
- expressions like $(D a == b) always uses $(D opEquals). If $(D opCmp)
567
- is defined but $(D opEquals) isn't, the compiler will supply a default
568
- version of $(D opEquals) that performs member-wise comparison. If this
569
- member-wise comparison is not consistent with the user-defined
570
- `opCmp`, then it is up to the programmer to supply an appropriate
571
- version of $(D opEquals). Otherwise, inequalities like $(D a <= b)
566
+
567
+ $(P Note that $(D opCmp) is only used for
568
+ $(GLINK2 expression, RelExpression) operators;
569
+ expressions like $(D a == b) always use $(RELATIVE_LINK2 equals, `opEquals`).)
570
+
571
+ $(P For structs, if $(D opCmp) is defined but $(D opEquals) isn't,
572
+ the compiler will supply $(DDSUBLINK spec/expression, struct_equality, a default
573
+ version) of $(D opEquals) that performs member-wise comparison. However, the
574
+ member-wise comparison may not be consistent with the user-defined
575
+ `opCmp`.)
576
+
577
+ $(P It is up to the programmer to also supply a
578
+ version of $(D opEquals) when appropriate. Otherwise,
579
+ a *RelExpression* like $(D a <= b)
572
580
will behave inconsistently with equalities like $(D a == b).)
573
581
574
582
$(SPEC_RUNNABLE_EXAMPLE_RUN
0 commit comments