www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1390] New: Implicit Instantiation: delegate args from 2 template params

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

           Summary: Implicit Instantiation: delegate args from 2 template
                    params
           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


This is the first of a pair of implicit-instantiation-of-function issues I'm
going to open.  I don't know whether I should list them as bugs or feature
requests.  I'm going to open them as bugs, and they can be changed if
appropriate.



I stumbled across this problem when I tried to build a CurryTail template
(curry the *last* argument from a delegate).  In the code below, CurryTailAlt
will perform implicit template instantiation, but I don't like it because one
delegate argument (the tail argument) shows up in both the P and T template
parameters.  It seems to me that DMD could deduce the template parameters in my
preferred version (CurryTail):


CODE
===========
void delegate(U) CurryTail(A,U...)(void delegate(U,A) dg,A arg)
{
  return null;
}
void delegate(T[0..$-1]) CurryTailAlt(P,T...)(void delegate(T) dg,P arg)
{
  return null;
}

struct FooStruct
{
  void foo(uint i,char c) {}
}

void bar() {
  auto temp = new FooStruct;

  auto dg1 = CurryTail   !(char,uint)(&temp.foo, 'c'); // this works
  auto dg2 = CurryTailAlt            (&temp.foo, 'c'); // this works
  auto dg3 = CurryTail               (&temp.foo, 'c'); // this doesn't
}
=============

DMD OUTPUT
=============
implicit_instantiation1.d(20): template
implicit_instantiation1.CurryTail(A,U...) does not match any template
declaration
implicit_instantiation1.d(20): template
implicit_instantiation1.CurryTail(A,U...) cannot deduce template function from
argument types (void delegate((uint), char),char)
[russ russ dmd_bugs]$ dmd -c implicit_instantiation1.d
implicit_instantiation1.d(20): template
implicit_instantiation1.CurryTail(A,U...) does not match any template
declaration
implicit_instantiation1.d(20): template
implicit_instantiation1.CurryTail(A,U...) cannot deduce template function from
argument types (void delegate((uint), char),char)


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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|1.020                       |D1 & D2
            Summary|Implicit Instantiation:     |Implicit Instantiation:
                   |delegate args from 2        |delegate args from variadic
                   |template params             |template argument



Reduced test case.
------
void bug1390a(A,U)(void delegate(U,A) dg, A arg)
{}
void bug1390(A,U...)(void delegate(U,A) dg, A arg)
{}

struct FooStruct   {
      void foo(uint i,char c) {}
}

void bar1390() {
    auto temp = new FooStruct;

    bug1390a!(char,uint)(&temp.foo, 'c');
    bug1390a            (&temp.foo, 'c');

    bug1390!(char,uint)(&temp.foo, 'c');
    bug1390            (&temp.foo, 'c');
}
----
The '1390a' cases work, but on D1, the second '1390' fails. On D2 *both* of the
'1390' instantiations fail.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 26 2012