www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1292] New: Template argument deduction doesn't work

reply d-bugmail puremagic.com writes:

           Summary: Template argument deduction doesn't work
           Product: D
           Version: 1.016
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: onlystupidspamhere yahoo.se


  class B {}
  class D : B {}

  template foo(S, T : S) { }    // doesn't work
  // template foo(S, T : B) { } // this works for some reason

  alias foo!(B, D) bar;

Compiler output:

bug.d(7): template instance foo!(B,D) does not match any template declaration


I'm guessing here what should happen:

From http://www.digitalmars.com/d/template.html, Argument deduction:

The types of template parameters are deduced for a particular template
instantiation by comparing the template argument with the corresponding
template parameter.

For each template parameter, the following rules are applied in order
until a type is deduced for each parameter:

1. If there is no type specialization for the parameter, the type of
the parameter is set to the template argument.

  (S, T : S) -> (B, T : S)

2. If the type specialization is dependent on a type parameter, the
type of that parameter is set to be the corresponding part of the type

  (B, T : S) -> (B, T : B)

3. If after all the type arguments are examined there are any type
parameters left with no type assigned, they are assigned types
corresponding to the template argument in the same position in the

  (B, T : B) -> (B, D)

4. If applying the above rules does not result in exactly one type for
each template parameter, then it is an error.


Jun 25 2007
parent d-bugmail puremagic.com writes:

bugzilla digitalmars.com changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

Fixed DMD 1.018 and DMD 2.002

Jul 01 2007