Re: delegates with references to local strings

2012-06-02 Thread Tobias Pankrath
Thank you. That works.

Re: delegates with references to local strings

2012-06-02 Thread Artur Skawina
On 06/02/12 14:01, Tobias Pankrath wrote: > 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) > { >

Re: delegates with references to local strings

2012-06-02 Thread bearophile
Tobias Pankrath: How can I store the string of the current iteration with a delegate? You need to create a closure (D main returns 0 automatically): import std.stdio, std.string; void main() { auto lines = ["line A", "line B", "line C"]; void delegate()[] delegates; foreach (li

delegates with references to local strings

2012-06-02 Thread Tobias Pankrath
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);