Bug 5403 – foreach requires front to be a function in a range

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-01-03T07:25:00Z
Last change time
2012-07-14T19:27:03Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2011-01-03T07:25:54Z
This is a valid range: import std.range; struct S { int front; bool empty; void popFront() {empty = true;} } static assert(isInputRange!S); // compiles But this fails: void main() { S s; foreach(int i; s) { } } fails with the following error: Error: no property 'opApply' for type 'S' Error: opApply() function for S must return an int Change front to: @property int front() {return 0;} and it compiles. Clearly empty is not required to be a function, and there is no mention of any function requirements in the spec, it's just stated that they must be properties.
Comment #1 by yebblies — 2011-06-15T22:52:08Z
*** Issue 3295 has been marked as a duplicate of this issue. ***
Comment #2 by yebblies — 2011-07-03T04:28:43Z
Comment #3 by github-bugzilla — 2012-07-14T08:55:19Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/85511f3cca367fa0b1d49a4748f3f047ff138425 Fix Issue 5403 - foreach requires front to be a function in a range Allow using any reasonable symbol as front/back/empty. Remove references to the old range interface (head/toe/next/retreat) https://github.com/D-Programming-Language/dmd/commit/b33914398d44535296d9a80e50a3c3eeba70a0a0 Merge pull request #203 from yebblies/issue5403 Issue 5403 - foreach requires front to be a function in a range