www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1391] New: Implicit Instantiation: deducing 'int n' from the number of arguments

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1391

           Summary: Implicit Instantiation: deducing 'int n' from the number
                    of arguments
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: webmaster villagersonline.com


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)


-- 
Jul 31 2007
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1391






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;
    // ...
}


-- 
Aug 03 2007