Robert Jacques wrote: > On Thu, 30 Apr 2009 17:23:19 -0400, Rainer Deyke <rain...@eldwood.com> > wrote: >> It's possible to write a reference wrapper around a value type. It's >> also possible to write a value wrapper around a reference type. >> However, the former is both easier and more efficient than the latter. > > Yes and no. Yes, the deep copy mixin is more complex to write the first > time, but after that it's easy to use. And second, it's just as > efficient as the later, since the deep copy mixin generates the same > code as a value type.
A simple deep-copy struct wrapper around a class type is horribly inefficient compared to a direct struct type: - It uses an extra heap allocation per instance. - It uses an extra level of indirection. - It uses virtual function calls. - It allocates an extra reference to a virtual function table per instance. I suppose a very clever wrapper metaprogram or a really clever optimizing compiler might eliminate some of these inefficiencies. -- Rainer Deyke - rain...@eldwood.com