writeln, alias this and dynamic arrays.

Adam D. Ruppe destructionator at gmail.com
Fri Nov 17 13:13:53 UTC 2017


On Friday, 17 November 2017 at 06:57:16 UTC, Michael V. Franklin 
wrote:
> Actually, it looks like it's this 4-year old bug.  
> https://issues.dlang.org/show_bug.cgi?id=9506

Yeah, I suspected this is old and my comment in there still 
applies...

It passes the isInputRange test due to the implicit conversion of 
alias this, and then writeln takes it and consumes it.

One thing you might consider is making the alias this go to a 
getter property instead of the method directly. Then operations 
on it will work on a copy of the slice, and thus not consume the 
original one. But then you can't do stuff like append do it 
directly either...

imo writeln should check for .save and use it. But meh I don't 
care to personally bother fixing it and apparently nobody else 
does either.


More information about the Digitalmars-d-learn mailing list