@@ -383,19 +383,19 @@ $(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, the compiler provides a default version for structs
392
392
that does member-wise comparison. If this suffices, one may define only
393
- $(D opCmp) to customize the behaviour of the inequality operators. But
393
+ $(D opCmp) to customize the behaviour of the *RelExpression* operators. But
394
394
if not, then a custom version of $(D opEquals) should be defined as
395
395
well, in order to preserve consistent semantics between the two kinds
396
396
of comparison operators.)
397
397
398
- $(P Finally, if the user-defined type is to be used as a key in the
398
+ $(P Finally, if a user-defined type is to be used as a key in the
399
399
built-in associative arrays, then the programmer must ensure that the
400
400
semantics of $(D opEquals) and $(D toHash) are consistent. If not, the
401
401
associative array may not work in the expected manner.)
@@ -538,13 +538,20 @@ struct S
538
538
int opCmp(ref const S s) const { ... }
539
539
}
540
540
---
541
- $(P Note that $(D opCmp) is only used for the inequality operators;
542
- expressions like $(D a == b) always uses $(D opEquals). If $(D opCmp)
543
- is defined but $(D opEquals) isn't, the compiler will supply a default
544
- version of $(D opEquals) that performs member-wise comparison. If this
545
- member-wise comparison is not consistent with the user-defined
546
- `opCmp`, then it is up to the programmer to supply an appropriate
547
- version of $(D opEquals). Otherwise, inequalities like $(D a <= b)
541
+
542
+ $(P Note that $(D opCmp) is only used for
543
+ $(GLINK2 expression, RelExpression) operators;
544
+ expressions like $(D a == b) always use $(RELATIVE_LINK2 equals, `opEquals`).)
545
+
546
+ $(P For structs, if $(D opCmp) is defined but $(D opEquals) isn't,
547
+ the compiler will supply $(DDSUBLINK spec/expression, struct_equality, a default
548
+ version) of $(D opEquals) that performs member-wise comparison. However, the
549
+ member-wise comparison may not be consistent with the user-defined
550
+ `opCmp`.)
551
+
552
+ $(P It is up to the programmer to also supply a
553
+ version of $(D opEquals) when appropriate. Otherwise,
554
+ a *RelExpression* like $(D a <= b)
548
555
will behave inconsistently with equalities like $(D a == b).)
549
556
550
557
$(SPEC_RUNNABLE_EXAMPLE_RUN
0 commit comments