Problems with implicit template instantiation: Tail Currying
downs
default_357-line at yahoo.de
Wed Jul 18 14:24:11 PDT 2007
Russell Lewis wrote:
> I'm trying to write a template to perform function currying of the
> *last* argument to a delegate, and I can't get implicit instantiation to
> work with my template. Take a look at this example code:
>
> =======
> void delegate(U) Curry (A,U...)(void delegate(A,U) dg,A arg) {
> return delegate void(U) {};
> }
> void delegate(U) CurryTail(A,U...)(void delegate(U,A) dg,A arg) {
> return delegate void(U) {};
> }
> void foo() {
> void delegate(uint,char[],uint) dg;
> uint i;
> Curry (dg,i);
> CurryTail(dg,i);
> }
> =======
>
> The CurryTail call fails with the following errors:
>
> foo.d(11): template foo.CurryTail(A,U...) does not match any template
> declaration
> foo.d(11): template foo.CurryTail(A,U...) cannot deduce template
> function from argument types (void delegate(uint, char[], uint),uint)
>
>
>
> So: if the Curry() call works, why doesn't the CurryTail() call? Is
> this a bug, or some sort of design restriction?
>
> Russ
Try like so:
void delegate(T[0..$-1]) CurryTail(P, T...) (void delegate(T) dg, P arg) {
static assert(is(P: T[$-1]),
"Invalid type: "~P.toString~" cannot be converted to "~T[$-1].toString);
return delegate void(T[0..$-1] t) {};
}
More information about the Digitalmars-d
mailing list