Bug 1391 – Implicit Instantiation: deducing 'int n' from the number of arguments

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-07-31T13:42:45Z
Last change time
2019-08-08T13:26:11Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Russ Lewis

Comments

Comment #0 by webmaster — 2007-07-31T13:42:45Z
My 2nd of 2 implicit instantiation bugs. This one came about when I was trying to do implicit instantiation of a Curry template, where the user can pass more than one argument. The template wants to deduce the delegate arguments *and* the number of elements to curry. Note, in the code below, that DMD can deduce the contents of Tuple U from the arguments inside the delegate which is passed as the first argument, and can deduce the value of n by figuring out how many arguments were passed after that. I'm not saying it would be easy to code, just that it is possible for DMD to deduce this from the available information, and if it had, then my code would have worked. :) CODE ============ void delegate(U[n..$]) Curry(int n,U...)(void delegate(U) dg,U[0..n] args) { return null; } struct Foo { void f1(uint i) {} } void f2() { auto temp = new Foo; auto dg1 = Curry!(1,uint)(&temp.f1, cast(uint)0); auto dg2 = Curry (&temp.f1, cast(uint)0); } DMD OUTPUT =============== implicit_instantiation2.d(14): template implicit_instantiation2.Curry(int n,U...) does not match any template declaration implicit_instantiation2.d(14): template implicit_instantiation2.Curry(int n,U...) cannot deduce template function from argument types (void delegate((uint _param_1)),uint)
Comment #1 by kirklin.mcdonald — 2007-08-03T16:44:13Z
You can do this by rewriting the template like this: ReturnType!(dg_t) delegate(ParameterTypeTuple!(dg_t)[T.length .. $]) curry(dg_t, T...) (dg_t dg, T t) { alias ParameterTypeTuple!(dg_t) U; const uint n = T.length; // ... }
Comment #2 by razvan.nitu1305 — 2019-08-08T13:26:11Z
The compiler cannot tie n to the number of arguments that you are passing. There is just not sufficient information for that. Closing as WONTFIX.