Time to kill T() as (sometimes) working T.init alias ?

Jonathan M Davis jmdavisProg at gmx.com
Sun Dec 9 20:20:22 PST 2012


On Monday, December 10, 2012 05:12:17 Mehrdad wrote:
> On Monday, 10 December 2012 at 03:53:04 UTC, Walter Bright wrote:
> > I do not dispute that deep copy is commonly used in C++. I
> > challenge the idea that it is a good design pattern, i.e.
> > better than using copy-on-write.
> 
> Ignoring the design issue, it's plain faster -- for COW you have
> to perform checks on every call.

Well, if you're doing a lot of copying and very little mutating, then COW 
could end up being much faster if copying is expensive (strings types in C++ 
would probably be a good example of this). However, if you're doing a lot of 
mutating, then COW doesn't save you much (if anything) and definitely could end 
up costing you more with all of the extra checks. It all depends on the use 
case. Regardless, I think that the decision should be made by the programmer. 
If we want to do things to encourage better idioms or make them easier, then 
fine, but I don't think that it makes sense to get rid of being able to deep 
copy structs via a postblit or copy constructor. If anything, I think that  we 
need to _add_ copy constructors so that we can get around the impossibility of 
a const or immutable postblit.

- Jonathan M Davis


More information about the Digitalmars-d mailing list