Ruling out arbitrary cost copy construction?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 31 09:40:41 PDT 2010


On 10/31/10 3:38 AM, Dmitry Olshansky wrote:
> On 31.10.2010 6:56, Andrei Alexandrescu wrote:
> [snip]
>> Walter and I discussed the matter again today and we're on the brink
>> of deciding that cheap copy construction is to be assumed. This
>> simplifies the language and the library a great deal, and makes it
>> perfectly good for 95% of the cases. For a minority of types, code
>> would need to go through extra hoops (e.g. COW, refcounting) to be
>> compliant.
>>
>> I'm looking for more feedback from the larger D community. This is a
>> very important decision that marks one of the largest departures from
>> the C++ style. Taking the wrong turn here could alienate many
>> programmers coming from C++.
>>
>> So, everybody - this is really the time to speak up or forever be silent.
>>
>>
>> Andrei
>
> The only things I've ever seen in C++ _correctly_ using _costly_ copy
> constructor are containers and some bignums, but then most of the time
> one need to define swap for it to perform well in the std::sort for
> instance, and that is oftentimes forgotten.
> That indicates that containers are better off being reference types,
> which is what they are in D anyway, and bignums I do belive could use
> COW/small number optimization.
>
> I'd go with cheap constructors assumed given that it simplifies matters
> a lot.

I've been thinking of this too - costly copy construction requires 
constant attention in client and library code alike (e.g. STL 
containers) or is flat out in bad taste (e.g. the mythical Matrix class 
that returns copies from operators).

Andrei


More information about the Digitalmars-d mailing list