[Issue 5403] New: foreach requires front to be a function in a range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 3 07:28:07 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5403

           Summary: foreach requires front to be a function in a range
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-01-03 07:25:54 PST ---
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.

-- 
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