Alias lamda argument vs Type template argument

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 15 21:06:36 PDT 2015


On 16/10/15 4:02 PM, Freddy wrote:
> There are two these different ways to pass functions as template
> arguments. Which is preferred?
> ---
> void funcA(alias calle)()
> {
>      calle();
> }
>
> void funcB(T)(T calle)
> {
>      calle();
> }
>
> void main()
> {
>      funcA!(() => 0);
>      funcB(() => 0);
> }
> ---

Depends, do you need it at compile time or at runtime?
funcA is at compile time and funcB is at runtime.
If at runtime, you'll probably want to define it anyway and not bother 
with templates.

If you are passing it in for compile time, you are probably doing it for 
usage with traits. In any case, your better off calling by runtime args. 
Since you know the arguments and the return type. At least per your example.


More information about the Digitalmars-d-learn mailing list