www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9294] New: foreach tuple unpack with opApply

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

           Summary: foreach tuple unpack with opApply
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2013-01-11 10:47:04 PST ---
Since some time the D foreach is able to unpack tuples, as visible in the
main() regarding Foo1:


import std.typecons: Tuple;
alias Two = Tuple!(int, int);
struct Foo1 {
    bool empty = false;
     property Two front() { return Two(1, 2); }
    void popFront() { empty = true; }
}
struct Foo2 {
    int opApply(int delegate(ref Two) dg) {
        int result;
        auto aux = Two(1, 2);
        result = dg(aux);
        return result;
    }
}
void main() {
    foreach (x_y; Foo1()) {} // OK
    foreach (x, y; Foo1()) {} // OK
    foreach (x_y; Foo2()) {} // OK
    foreach (x, y; Foo2()) {} // line 21, error.
}



But currently in dmd v.2.062alpha the same doesn't happen for a tuple given by
opApply:

test.d(21): Error: cannot uniquely infer foreach argument types

Maybe it's better for the last foreach to be valid code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2013