First Draft: Implicit Type Template Instantiation via Constructors

Sebastiaan Koppe mail at skoppe.eu
Wed May 14 16:41:44 UTC 2025


On Wednesday, 14 May 2025 at 06:46:09 UTC, Meta wrote:
> On Tuesday, 13 May 2025 at 06:06:54 UTC, Sebastiaan Koppe wrote:
>> 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.
>>>
>>> [...]
>>>
>>> The DIP:
>>> https://github.com/MetaLang/DIPs/blob/dip1050/DIPs/DIP1050.md
>>
>> Makes a lot of sense to me.
>>
>> What about implicit constructors though?
>>
>> ```
>> struct Pair(T,U) {
>>     T t;
>>     U u;
>> }
>> void main() {
>>     auto p = Pair(1,"string");
>> }
>> ```
>
> That is not actually a constructor - it is struct literal 
> syntax. I did not realize there was a difference either until 
> recently.

Fair enough, but could the dip support it, or perhaps in the 
future? The fact that we both expected it was a constructor - and 
you could argue it actually is, on the grounds that it does in 
fact construct an object - suggests more users would expect it to 
work.


More information about the dip.development mailing list