Implicit Constructors

Q. Schroll qs.il.paperinik at gmail.com
Sat Oct 14 19:10:26 UTC 2017


On Friday, 13 October 2017 at 14:50:44 UTC, Adam D. Ruppe wrote:
> [snip]
> But actually, I really wish D just had implicit ctors on the 
> types themselves. I think C++'s mistake was that implicit was 
> the default, and you have to write `explicit`. If we did the 
> opposite, where implicit was opt in, I think it would be useful 
> without the worry C++ had.

Not completely. Walter and Andrei oppose even explicitly 
annotated implicit constructors [1, 2]. With my solution, you 
state a two sided desire, like offer and acceptance. Contrary to 
(even explicitly annotated, non-default) implicit constructors 
being the only necessity for getting implicit constructor calls, 
this makes it very transparent what's happening. The only 
exception is when `S` is in a library, you use @implicit(0) on 
it, and the supplier decides to add more @implicit constructors 
to `S`. This is what we (will) have @future [3] for.

[1] https://issues.dlang.org/show_bug.cgi?id=4875#c5
[2] https://issues.dlang.org/show_bug.cgi?id=7019#c8
[3] https://github.com/dlang/DIPs/blob/master/DIPs/DIP1007.md


More information about the Digitalmars-d mailing list