Bug 18546 – Improvement: Implicit Class Template Instantiation
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-02T00:56:08Z
Last change time
2018-03-02T13:58:19Z
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2018-03-02T00:56:08Z
Why does this not work? Should this work?
class Foo(T) {
this(T t) { }
}
auto foo = new Foo(5);
C++ can do it...
Comment #1 by issues.dlang — 2018-03-02T03:37:01Z
The normal solution is to use a factory function which can then take advantage of IFTI. As it stands, the compiler never does any implicit template instantations except for functions, because for templates that aren't function templates, it's ambiguous. This particular case is a bit special in that it's using the type, not a function, but it's also triggering the constructor, which _is_ a function. So, I don't know. Really, what it comes down to is that some specific cases of implicitly instantiating templated types could be made to work, but it can't work in the general case. So, thus far, the solution has been to simply not support it.
Related: issue #1012.
Comment #2 by schveiguy — 2018-03-02T13:58:19Z
*** This issue has been marked as a duplicate of issue 6082 ***