maybe i got a bug

Ali Çehreli acehreli at yahoo.com
Thu Jan 31 13:31:07 PST 2013


On 01/31/2013 08:59 AM, bioinfornatics wrote:
 > I think when i iterate over a phobos range :
 > foreach( state, letter; fastq )
 > and if fastq instance is called into this loop as done at line 181 is
 > not the same instance

Correct. Here is a simpler program:

import std.stdio;

struct S
{
     int i;

     @property int front() const
     {
         writefln("front   : %s", &i);
         return i;
     }

     @property bool empty() const
     {
         writefln("empty   : %s", &i);
         return i == 0;
     }

     void popFront()
     {
         writefln("popFront: %s", &i);
         --i;
     }
}

void main()
{
     auto s = S(2);
     writefln("main    : %s", &s.i);

     foreach (i; s) {
     }
}

The object in main is a different object:

main    : 7FFFBD429B70
empty   : 7FFFBD429B74
front   : 7FFFBD429B74
popFront: 7FFFBD429B74
empty   : 7FFFBD429B74
front   : 7FFFBD429B74
popFront: 7FFFBD429B74
empty   : 7FFFBD429B74

Ali



More information about the Digitalmars-d-learn mailing list