Help, what is the code mean?

Ali Çehreli acehreli at yahoo.com
Tue Apr 28 21:19:41 UTC 2020


On 4/28/20 1:48 PM, Net wrote:
 > () { ... } ();
 >
 > Is there a name of this kind of function in D? unnamed? anonymous?

Lambda or anonymous function.[1]

Note that the last () is not part of the definition but the execution of 
the function.

This idiom is used for initializing e.g. a const variable with 
non-trivial code as well (in C++ as well):

const a = {
     // ... some complex logic ...
     return result;
   }();

Ali

[1] I have a page that shows different syntaxes for lambda functions:

   http://ddili.org/ders/d.en/lambda.html#ix_lambda.=%3E



More information about the Digitalmars-d-learn mailing list