IFTI -- implicit function template instantiation -- is a pretty nifty feature in D, which allows code that calls templated functions to be written in a nice, clear way.

Would it be possible to extend it to also work for class/struct construction, so that the type of a templated class can be deduced from its constructor's arguments? Here's an example of what I mean:

  class Foo(T)
  {
      T bar;
      this(T t) { bar = t; }
  }

  auto foo = new Foo(1.0);  // The type of foo is now Foo!double

I've found myself wishing for this in several cases. Sometimes the template specification has been so involved that I've ended up writing factory methods instead of ordinary constructors. But then, the classes in question become inconsistent with the rest of my code, and I hate inconsistencies.

I've only seen this mentioned once before, in bug report 1856, but none of the comments in that report say anything more about it.

  http://d.puremagic.com/issues/show_bug.cgi?id=1856

Are there specific reasons why ICTI and ISTI wouldn't work?

-Lars

Reply via email to