Copy Constructor DIP

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Fri Jul 13 14:12:59 UTC 2018


On 7/13/18 8:31 AM, Atila Neves wrote:
> On Friday, 13 July 2018 at 03:01:25 UTC, Manu wrote:
>> On Thu, 12 Jul 2018 at 19:15, Andrei Alexandrescu via Digitalmars-d 
>> <digitalmars-d at puremagic.com> wrote:
>>>
>>> On 7/12/18 6:34 PM, Manu wrote:
>>> > On Thu, 12 Jul 2018 at 06:50, Andrei Alexandrescu via > 
>>> Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>> >>
>> [..]
>> doesn't perform copy construction?
>>   1. the function is highly unlikely to exist because postblit; it's a
>> meaningless function to write. are there any known instances of that
>> signature in the wild?
> 
> https://github.com/search?q=%22this%5C%28ref%22+language%3AD&type=Code
> 
> The answer seems to be: not many. Most of the results above are false 
> positives because github won't let me escape the left parenthesis.

A proposal that just works without any user intervention would 
definitely be attractive.

The drawback is silent modification of code behavior. Consider:

import std.stdio;
struct A {
     this(ref immutable A obj) { writeln("x"); }
}
void main()
{
     immutable A a1;
     A a2 = A(a1);
     A a3 = a1;
}

With the current language, "x" is printed once. If we make the ctor 
implicit, "x" is printed twice.

In the "levels of hell" of semantics changes, probably the nicest is 
allowing code to compile that previously didn't. Then, refusing to 
compile code that previously did would be definitely bad. But if you 
want to drink the cup of disgrace to the bottom, you must reach for 
silent change of behavior.


More information about the Digitalmars-d mailing list