http://d.puremagic.com/issues/show_bug.cgi?id=4347
Summary: foreach over range should save range. Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: dsim...@yahoo.com --- Comment #0 from David Simcha <dsim...@yahoo.com> 2010-06-19 08:49:42 PDT --- To be consistent with the old definition of forward ranges, and with arrays and opApply-based ranges, a foreach loop should call save() if it's available. The example below demonstrates why not doing so is problematic. import std.stdio; class SomeRange { uint num; uint front() { return num; } void popFront() { num++; } bool empty() @property { return num >= 10; } typeof(this) save() @property { auto ret = new typeof(this); ret.num = num; return ret; } } void main() { auto r = new SomeRange; foreach(elem; r) { writeln(elem); // Prints numbers 0-9. } foreach(elem; r) { writeln(elem); // Nothing. } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------