Bug 21106 – Add type inference for constructor calls
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-03T21:49:30Z
Last change time
2020-08-04T08:25:01Z
Assigned to
No Owner
Creator
Victor Porton
Comments
Comment #0 by porton — 2020-08-03T21:49:30Z
I propose to add type inference (similar to one for functions) for constructor calls, that is to make the following program legal:
class C(T) {
this(T) { }
}
void main() {
immutable x = new C(0);
}
This would simplify programming eliminating the need to create a factory function or factory functions for each template class.
Pro: shorter programs.
Con: some consider it a good practice to make a factory function ALWAYS.
Pro: even if you create a factory function, the body of this function itself would be shortened.
Comment #1 by simen.kjaras — 2020-08-04T08:25:01Z
*** This issue has been marked as a duplicate of issue 1997 ***