Passing functions to functionals
Jesse Phillips
jessekphillips+D at gmail.com
Tue Nov 30 15:09:08 PST 2010
Lars T. Kyllingstad Wrote:
> // Same as above, using template alias parameter.
> auto eval(alias f, X)(X x) { return f(x); }
>
> // Test
> void main()
> {
> int add2(int i) { return i + 2; }
> assert (eval!add2(1) == 3);
> }
>
> I'd be grateful if people would share their knowledge of the pros and
> cons of each method. For instance, are there any situations where
> template alias parameters don't work?
>
>
> Thanks,
>
> -Lars
Well, with using an alias parameter then std.functional.unaryFun/binaryFun is usable so you could use the eval!"a+2"(5) syntax.
More information about the Digitalmars-d-learn
mailing list