Copy Constructor DIP

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jul 12 14:10:47 UTC 2018


On 07/12/2018 09:49 AM, Atila Neves wrote:
> On Thursday, 12 July 2018 at 06:54:37 UTC, RazvanN wrote:
> 
>> [...]
> 
>> If by "come in pairs" you mean that you can define them both, then yes,
>> that is the case. Will add a paragraph in the DIP to specify this.
>>
>> You mentioned that it's terrible that the assignment operator
>> and the copy constructor come in pairs. Why is that? Would you rather
>> have a copy constructor that is used also as an assignment operator?
> 
> Because, like in C++, now you have to implement both and make sure they 
> do the same thing. Boilerplaty and a recipe for disaster.
> 
> Atila

There's no meaningful way to avoid that. The two operations are 
fundamentally different, are typechecked differently, and actually are 
different in the presence of qualifiers on fields.

Introspection is a key helper here compared to C++.


More information about the Digitalmars-d mailing list