digitalmars.D.learn - Re: Problem with templates
- Sean Reque <seanthenewt yahoo.com> Jul 07 2008
- BCS <ao pathlink.com> Jul 07 2008
Jarrett Billingsley Wrote:"Sean Reque" <seanthenewt yahoo.com> wrote in message news:g4tjei$31ci$1 digitalmars.com...Never mind, I wrote the function wrong. This actually works. Alpha compilers have terrible error messages sometimes! import std.stdio; /* R is return type * A is first argument type * U is TypeTuple of rest of argument types */ R delegate(U) Curry(R, A, U...)(R delegate(A, U) dg, A arg) { return delegate R(U args) { return dg(arg, args); }; } void main() { int plus(int x, int y, int z) { return x + y + z; } auto plus_two = Curry(&plus, 2); writefln("%d", plus_two(6, 8)); // prints 16 }
Of course it works, plus is a delegate :) Now put "static" in front of the declaration of plus and watch it fail.
Ohhhhh.. I thought you had to use the delegate keyword to make something a delegate, or otherwise it was a function by default. Guess I need to read the docs more carefully.
Jul 07 2008
Reply to Sean,Of course it works, plus is a delegate :) Now put "static" in front of the declaration of plus and watch it fail.
something a delegate, or otherwise it was a function by default. Guess I need to read the docs more carefully.
Short test for delegate vs. fn ptr: If you can reference any non-static, non-global, non-local values, it will be a delegate.
Jul 07 2008