digitalmars.D - Problems with implicit template instantiation: Tail Currying
- Russell Lewis (25/25) Jul 18 2007 I'm trying to write a template to perform function currying of the
- downs (7/39) Jul 18 2007 Try like so:
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
Jul 18 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) {};
}
Jul 18 2007








downs <default_357-line yahoo.de>