Why do associative arrays return from opIndexAssign by value?

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 18 03:18:07 PDT 2013


On Tuesday, June 18, 2013 11:41:03 TommiT wrote:
> On Tuesday, 18 June 2013 at 09:28:04 UTC, Jonathan M Davis wrote:
> > Assignment operators definitely should return lvalues normally.
> > I don't know
> > why deadalnix would think otherwise. It's pretty much the norm
> > in C++, and I
> > see no reason for it to be different in D. No, it doesn't work
> > for all types,
> > but in the general case, it should.
> 
> At least int assignment isn't lvalue. I find this quite
> surprising:
> 
> void edit(ref int) { }
> 
> void main()
> {
>      int n;
>      //edit(n = 4); // Error
>      edit(n += 4);
> }

Maybe that's by design, but it's not what I would have expected. I don't know 
if that's a bug or not. Certainly, it doesn't match how it works in C++, and I 
don't know why D would be any different in this regard.

- Jonathan M Davis


More information about the Digitalmars-d mailing list