Just one time
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue Oct 20 11:08:33 PDT 2015
    
    
  
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;
import std.algorithm;
void firstStep() {
     writeln("First call!");
     takeAStep = &followingSteps;
}
void followingSteps() {
     writeln("Just another call");
}
auto takeAStep = &firstStep;
void main() {
     3.iota.each!(_ => takeAStep());
}
First call!
Just another call
Just another call
Ali
    
    
More information about the Digitalmars-d-learn
mailing list