Skip to content

Commit 32738eb

Browse files
authored
[spec/expression] Add struct equality example (#4219)
Also add 2 links.
1 parent 57c66cd commit 32738eb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

spec/expression.dd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,21 @@ $(GNAME EqualExpression):
686686
results of the corresponding object fields.
687687
)
688688

689+
$(SPEC_RUNNABLE_EXAMPLE_RUN
690+
---
691+
struct S
692+
{
693+
int i = 4;
694+
string s = "four";
695+
}
696+
697+
S s;
698+
assert(s == S());
699+
s.s = "foul";
700+
assert(s != S());
701+
---
702+
)
703+
689704
$(IMPLEMENTATION_DEFINED The contents of any $(DDSUBLINK spec/struct, struct_layout,
690705
alignment gaps) in the struct object.)
691706

spec/struct.dd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,9 @@ void main()
25342534
---
25352535
)
25362536

2537-
$(P If a struct declaration defines an $(D opCmp) or $(D opEquals)
2537+
$(P If a struct declaration defines an
2538+
$(DDSUBLINK spec/operatoroverloading, compare, `opCmp`) or
2539+
$(DDSUBLINK spec/operatoroverloading, equals, `opEquals`)
25382540
method, it will take precedence to that of the *AliasThis* member. Note
25392541
that, unlike an $(D opCmp) method, an $(D opEquals) method is implicitly
25402542
defined for a $(D struct) declaration if a user-defined one isn't provided.

0 commit comments

Comments
 (0)