[Issue 15582] Slice returned by opSlice() not accepted as lvalue

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jan 21 14:23:37 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15582

--- Comment #3 from b2.temp at gmx.com ---
(In reply to Marc Schütz from comment #2)
> (In reply to b2.temp from comment #1)
> > I don't aggree, it's like if you say that
> > 
> > s.opSlice() = 10;
> > 
> > should work.
> 
> That should work, too.
> 
> Note that appending another pair of brackets is already accepted. As long as
> there's no ambiguity with assigning to the slice itself (i.e. the lhs is not
> an lvalue, and opSlice doesn't return by ref), it should just do the
> appropriate element-wise operation.
> 
> Analogously with *=, += etc.

Actually you overload the wrong operator, because this works:

struct S {
    int[10] data;
    void opIndexAssign(int v) {data[] = v;}
}

void main() {
    S s;
    s[] = 10;
} 

So I suggest you to close the issue.

--


More information about the Digitalmars-d-bugs mailing list