[Issue 3514] opApply should be the first-choice foreach iteration method.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 16 13:07:45 PST 2009


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


Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |


--- Comment #4 from Steven Schveighoffer <schveiguy at yahoo.com> 2009-11-16 13:07:44 PST ---
This bug supersedes bug 2984, because solving this bug will not only address
the problem in 2984, but address a very important problem that is not
identified in 2984.  That is:  if opApply is present *at all* it should
override any range functionality when sending to foreach.  This includes the
case not identified in 2984 in which valid range operations are present
*alongside* opApply.  e.g.:

import std.stdio;

struct S
{
    int front()
    {
        return 0;
    }

    bool empty()
    {
        return true;
    }

    void popFront()
    {
    }

    int opApply(int delegate(ref int x) dg)
    {
        writeln("inside opapply");
        int x = 0;
        return dg(x);
    }
}

void main()
{
    S s;
    foreach(i; s)
    {
        writeln("inside loop %d", i);
    }
}

Currently outputs nothing, it should output:
inside opapply
inside loop 0

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