How to declare an alias to a function literal type
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue Jan 12 08:25:37 PST 2016
    
    
  
On 01/12/2016 07:41 AM, ParticlePeter wrote:
 > Please, if possible, also show me where I should have found the answer
 > (D Reference, Alis book
It is not used with a function literal but searching for 'alias' below 
yields something close: :)
   http://ddili.org/ders/d.en/lambda.html
<quote>
Function pointer syntax is relatively harder to read; it is common to 
make code more readable by an alias:
alias CalculationFunc = int function(char, double);
That alias makes the code easier to read:
     CalculationFunc ptr = &myFunction;
As with any type, auto can be used as well:
     auto ptr = &myFunction;
</quote>
As others have already said, &myFunction can be replaced with a lambda. 
Shamefully without compiling:
     auto ptr = (char, double) => 42;
Ali
    
    
More information about the Digitalmars-d-learn
mailing list