[Issue 11935] New: Allow `ref` in front tuple expansion in `foreach` over range iff `front` returns by `ref`

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 15 23:49:33 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11935

           Summary: Allow `ref` in front tuple expansion in `foreach` over
                    range iff `front` returns by `ref`
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2014-01-16 11:49:31 MSK ---
Test code:
---
import std.typecons;

struct S1
{
    @property bool empty();
    @property Tuple!(int, int) front();
    void popFront();
}

struct S2
{
    @property bool empty();
    @property ref Tuple!(int, int) front();
    void popFront();
}

void main()
{
    static assert( __traits(compiles, { foreach(    a,     b; S1()) { } }));
    static assert(!__traits(compiles, { foreach(ref a, ref b; S1()) { } }));
    static assert( __traits(compiles, { foreach(ref a, ref b; S2()) { } }));
}
---

This issue is for front tuple expansion only. For regular `foreach` over range
see Issue 11934.

Also Issue 11929 is a simplified variant proposing just disable `ref` in front
tuple expansion case because in general created tuple is a temporary. It should
be WONTFIX-ed if this one is fixed.

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


More information about the Digitalmars-d-bugs mailing list