[Issue 4707] auto ref for foreach loops
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 2 03:10:27 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4707
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #5 from monarchdodra at gmail.com 2013-11-02 03:10:11 PDT ---
(In reply to comment #4)
> This is still an interesting proposal.
Seconded. Thoguh I do seem to remember that another Bug Report about this was
open... I did find this interesting thread about it though:
http://forum.dlang.org/thread/ceftaiklanejfhodbpix@forum.dlang.org
This proposal has 2 very important (IMO) ramifications:
First, it would allow making "foreach(ref; range)" illegal, if said range
doesn't give ref access. This is a *big* source of bugs.
Second, once we have this, we would be able to write *correct* generic code.
Read this extract from "reduce":
// For now, just iterate using ref to avoid unnecessary copying.
// When Bug 2443 is fixed, this may need to change.
foreach (ref elem; r)
{
Or "I'm doing wrong, but it seems to work".
So long story short, if we ever hope to have "ref-correct" foreach, we *must*
have "auto ref" to make foreach useable in generic code.
This gets a vote from me
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list