D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21106 - Add type inference for constructor calls
Summary: Add type inference for constructor calls
Status: RESOLVED DUPLICATE of issue 1997
Alias: None
Product: D
Classification: Unclassified
Component: dlang.org (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-03 21:49 UTC by Victor Porton
Modified: 2020-08-04 08:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Victor Porton 2020-08-03 21:49:30 UTC
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 Simen Kjaeraas 2020-08-04 08:25:01 UTC

*** This issue has been marked as a duplicate of issue 1997 ***