www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8614] New: Cannot change the iteration index during CTFE

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8614

           Summary: Cannot change the iteration index during CTFE
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: philippe.sigaud gmail.com



19:22:36 CEST ---
During runtime execution of a foreach loop, you can change the index. This
doesn't work at compile-time and gives a different result when foo is called
through CTFE or at runtime:


import std.stdio;
int[] foo(int[] data) 
{
     foreach (i, ref x; data) {
         x++;
         i++;
     }
     return data;
}

void main() 
{
    // Compile-time
    enum result1 = foo([10, 20, 30, 40]);
    assert(result1 == [11, 21, 31, 41]);

    // Runtime
    auto result2 = foo([10, 20, 30, 40]);
    assert(result2 == [11, 20, 31, 40]);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8614


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |timon.gehr gmx.ch
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 8498 ***

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