Re: Just one time

2015-10-21 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 18:08:33 UTC, Ali Çehreli wrote: On 10/20/2015 08:48 AM, Andrea Fontana wrote: It happens I need to perform an operation just one time (inside a function, a loop...) An idea that uses a function pointer where the first step does its task and then sets the

Re: Just one time

2015-10-20 Thread Ali Çehreli via Digitalmars-d-learn
On 10/20/2015 08:48 AM, Andrea Fontana wrote: It happens I need to perform an operation just one time (inside a function, a loop...) An idea that uses a function pointer where the first step does its task and then sets the stage for the following steps: import std.stdio; import std.range

Re: Just one time

2015-10-20 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 16:01:58 UTC, Andrea Fontana wrote: On Tuesday, 20 October 2015 at 15:55:47 UTC, John Colvin wrote: Be aware that there will be one instance of val per thread, so you are detecting the first run in each thread, not in the program overall. This is the kind of thi

Re: Just one time

2015-10-20 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 15:55:47 UTC, John Colvin wrote: Be aware that there will be one instance of val per thread, so you are detecting the first run in each thread, not in the program overall. This is the kind of thing I'm interested in. What happens if I call isFirstTime!"test" acr

Re: Just one time

2015-10-20 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 15:48:47 UTC, Andrea Fontana wrote: It happens I need to perform an operation just one time (inside a function, a loop...) I wonder if doing this it's a good idea or not. bool isFirstTime(alias T)() { static val = true; if

Just one time

2015-10-20 Thread Andrea Fontana via Digitalmars-d-learn
It happens I need to perform an operation just one time (inside a function, a loop...) I wonder if doing this it's a good idea or not. bool isFirstTime(alias T)() { static val = true; if (val) { val = false; return