www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1997] New: Better type inference for templated types

reply d-bugmail puremagic.com writes:

           Summary: Better type inference for templated types
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: simen.kjaras gmail.com

In the following code, a shortcoming of current type inference is pointed out:

struct foo(T)
  T data;

  static foo!(T) opCall(T t)
    foo!(T) result;
    result.data = t;
    return result;

auto f = foo(4);

The line with 'f = foo(4)' gives a template instantiation error, while it
should be possible for the compiler to infer the template parameters from the

auto g = foo!(int)(4);

This works, but is nowhere near as pretty.

Apr 15 2008
parent d-bugmail puremagic.com writes:

Jesse Phillips <Jesse.K.Phillips+D gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |Jesse.K.Phillips+D gmail.co
                   |                            |m
            Version|unspecified                 |2.041

--- Comment #1 from Jesse Phillips <Jesse.K.Phillips+D gmail.com> 2010-03-10
08:46:35 PST ---
DMD includes private methods when it tries to match for type inference even
though the private function is not available.

.\test.d(10): Error: template bar.Bar(T) does not match any function template
.\test.d(10): Error: template bar.Bar(T) cannot deduce template function from
argument types !()(void delegate())

module bar;

import foo;

void Bar(T)(void delegate(T) call) {

void main() {
   auto foo = new Foo();

module foo;

class Foo {
   private void fish() {
   public void fish(string color) {

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2010