delegates with references to local strings
    Tobias Pankrath 
    tobias at pankrath.net
       
    Sat Jun  2 05:01:04 PDT 2012
    
    
  
consider this:
------------
import std.stdio;
import std.string;
alias void delegate() dlgt;
int main()
{
         dlgt[] dgs;
         string[] lines = ["line A", "line B", "line C"];
         foreach(line; lines)
         {
                 writeln(line);
                 dgs ~=  { writeln(line); };
         }
         foreach(dg; dgs) { dg(); }
         return 0;
}
-----------
It prints every line in line and stores a delegate that does the 
same.
The output is:
line A
line B
line C
line C
line C
line C
I want it to print every line twice. How can I store the string 
of the current iteration with a delegate? I tried dup'ing into a 
local, which didn't help.
Thank you for your advice.
    
    
More information about the Digitalmars-d-learn
mailing list