If I have the following class:
class A(T)
{
this(T t) {}
}
I must specify the class type in order to call its constructor:
auto a = new A(1); // error
auto b = new A!int(1); // ok
But IFTI works in this instance:
template foo(T)
{
void foo(T t) {}
}
I see little difference between the first and second cases -- both must be partially instantiated by the compiler to determine if there is a valid function to call.
Further supporting this, I can add a factory function:
A(T) createA(T)(T t) { return new A!T(t); }
which now is callable via IFTI:
auto a = createA(1); // ok.
It seems like the necessary logic is present in the compiler, it just needs to be utilized during a constructor call.
The same should apply to structs.
*** Issue 13196 has been marked as a duplicate of this issue. ***
Comment #3 by b2.temp — 2016-09-11T13:31:03Z
*** Issue 16465 has been marked as a duplicate of this issue. ***
Comment #4 by schveiguy — 2018-03-02T13:58:19Z
*** Issue 18546 has been marked as a duplicate of this issue. ***
Comment #5 by dlang-bot — 2024-10-02T15:31:02Z
@dkorpel created dlang/dmd pull request #16910 "[WIP] Fix bugzilla 6082 - Constructors of templated types should be callabl…" fixing this issue:
- Fix bugzilla 6082 - Constructors of templated types should be callable via IFTI
https://github.com/dlang/dmd/pull/16910
Comment #6 by robert.schadek — 2024-12-13T17:55:21Z