alias parameters, what for?

Dennis dkorpel at gmail.com
Thu May 9 11:35:37 UTC 2019


On Thursday, 9 May 2019 at 09:52:21 UTC, XavierAP wrote:
> alias parameters are used for functions (in the general sense). 
> Why this instead of specifying and typing the parameter 
> functions or delegates?

With function pointers, there is extra indirection and the 
function can not be inlined.
With alias parameters, something like map!(x => x*2) can be as 
fast as a hand-written for-loop. A function pointer would make it 
significantly slower since every multiplication adds a new 
function call. You can not have a variable map function to the 
alias parameter, but most often you don't need that. If you do, 
you can simply do map!(x => dynamicFunc(x)).


More information about the Digitalmars-d-learn mailing list