First Draft: Implicit Type Template Instantiation via Constructors

12345swordy alexanderheistermann at gmail.com
Thu Mar 20 18:01:05 UTC 2025


On Wednesday, 12 March 2025 at 00:20:55 UTC, Meta wrote:
> This DIP is a partial resurrection of DIP 40 
> (https://wiki.dlang.org/DIP40) by me and Dennis Korpel. Dennis 
> is working on the implementation 
> (https://github.com/dlang/dmd/pull/16910) while I am writing 
> the DIP.
>
> The purpose of this DIP is to propose a new avenue for Implicit 
> Template Instantiation (ITI) via constructors. Currently (that 
> I'm aware of) D only does Implicit _Function_ Template 
> Instantiation (IFTI); the proposal is to extend this implicit 
> instantiation to types as well, via their constructors.
>
> Before this DIP:
> ```d
> struct Pair(T, U)
> {
>     T t;
>     U u;
>
>     this(T t, U u)
>     {
>         this.t = t;
>         this.u = u;
>     }
> }
>
> void main()
> {
>     auto p1 = Pair(1, "asdf"); // Error: struct `Pair` is not 
> callable using argument types `!()(int, string)`
>                                // Candidate is: `Pair(T, U)`
> }
> ```
>
> After this DIP:
> ```
> struct Pair(T, U)
> {
>     T t;
>     U u;
>
>     this(T t, U u)
>     {
>         this.t = t;
>         this.u = u;
>     }
> }
>
> void main()
> {
>     auto p1 = Pair(1, "asdf"); // Okay, T is deduced as int and 
> U as string
> }
>
> ```
>
> The DIP:
> https://github.com/MetaLang/DIPs/blob/dip1050/DIPs/DIP1050.md

You spell "Changes" wrong, you better fixed that.

It is a straight up massive miss opportunity to not handle 
Partial template parameter deduction here. C++ doesn't even 
handle that edge case which due to that you had to resort to an 
all or nothing in C++, which can be very annoying at times.


More information about the dip.development mailing list