Problem with templates
Sean Reque
seanthenewt at yahoo.com
Mon Jul 7 10:27:44 PDT 2008
Jarrett Billingsley Wrote:
> "Sean Reque" <seanthenewt at yahoo.com> wrote in message
> news:g4tjei$31ci$1 at 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.
More information about the Digitalmars-d-learn
mailing list