Skip to content

Commit e621884

Browse files
pbackusdlang-bot
authored andcommitted
Fix issue 22417 - Slice assignment operator overloading example is incorrect
Also update the surrounding exposition to match the corrected example, and change some identifiers in the example to match the notation used in the exposition and the comments.
1 parent 4195a4d commit e621884

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

spec/operatoroverloading.dd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ $(H3 $(LNAME2 slice_assignment_operator, Slice Assignment Operator Overloading))
602602
`opIndexAssign` member function that takes the return value of the
603603
`opSlice` function as parameter(s).
604604
Expressions of the form $(CODE a[)$(SLICE)$(D ] = c) are rewritten as
605-
$(CODE a.opIndexAssign$(LPAREN)c,) $(D a.opSlice$(LPAREN))$(SLICE2)$(D $(RPAREN)$(RPAREN)),
605+
$(CODE a.opIndexAssign$(LPAREN)c,) $(D a.opSlice!0$(LPAREN))$(SLICE2)$(D $(RPAREN)$(RPAREN)),
606606
and $(CODE a[] = c) as $(CODE a.opIndexAssign(c)).
607607
)
608608

@@ -613,23 +613,23 @@ $(H3 $(LNAME2 slice_assignment_operator, Slice Assignment Operator Overloading))
613613
-------
614614
struct A
615615
{
616-
int $(CODE_HIGHLIGHT opIndexAssign)(int v); // overloads a[] = v
617-
int $(CODE_HIGHLIGHT opIndexAssign)(int v, size_t[2] x); // overloads a[i .. j] = v
618-
int[2] $(CODE_HIGHLIGHT opSlice)(size_t x, size_t y); // overloads i .. j
616+
int opIndexAssign(int v); // overloads a[] = v
617+
int opIndexAssign(int v, size_t[2] slice); // overloads a[i .. j] = v
618+
size_t[2] opSlice(size_t dim)(size_t i, size_t j); // overloads i .. j
619619
}
620620

621621
void test()
622622
{
623623
A a;
624624
int v;
625625

626-
a$(CODE_HIGHLIGHT []) = v; // same as a.opIndexAssign(v);
627-
a$(CODE_HIGHLIGHT [)3..4$(CODE_HIGHLIGHT ]) = v; // same as a.opIndexAssign(v, a.opSlice(3,4));
626+
a[] = v; // same as a.opIndexAssign(v);
627+
a[3..4] = v; // same as a.opIndexAssign(v, a.opSlice!0(3,4));
628628
}
629629
-------
630630

631631
$(P For backward compatibility, if rewriting $(D a[)$(SLICE)$(D ]) as
632-
$(D a.opIndexAssign$(LPAREN)a.opSlice$(LPAREN))$(SLICE2)$(D $(RPAREN)$(RPAREN))
632+
$(D a.opIndexAssign$(LPAREN)a.opSlice!0$(LPAREN))$(SLICE2)$(D $(RPAREN)$(RPAREN))
633633
fails to compile, the legacy rewrite
634634
$(D opSliceAssign$(LPAREN)c,) $(SLICE2)$(D $(RPAREN)) is used instead.
635635
)

0 commit comments

Comments
 (0)