Developing a plan for D2.0: Getting everything on the table
Brad Roberts
braddr at bellevue.puremagic.com
Mon Jul 27 11:25:53 PDT 2009
On Mon, 27 Jul 2009, Andrei Alexandrescu wrote:
> Bill Baxter wrote:
> > The requirement to add the post-blit is a little annoying. If a
> > ValueContainer is made fundamental and it is built initially out of
> > components with value semantics, then no explicit post-blit will be
> > necessary. However if you go the other way and start with a
> > RefContainer then a post-blit will be necessary when you implement the
> > ValueContainer based on it. So to me it seems a little better to go
> > with the ValueContainer as the base implementation.
>
> I think it's a matter of the most frequent use. I used to be a staunch
> supporter of values for containers, until Walter revealed to me that in STL
> you have value containers to constantly worry about adding the "&" everywhere.
> Implicitly copying containers is 95% of cases an error in C++ code. Witness
> all that advice about pass by reference etc. So why make that the default, one
> might ask? Better go with the flow and make the default case the easy case
> (reference), and if someone does want a value, have them write
> Value!Container.
>
>
> Andrei
There's two layers to talk about, the container itself and the elements it
contains. I agree that the container itself should be ref given the above
logic (which matches my experience). The less obvious one, imho, is the
default of the contained. Again, c++ uses value containership, but an
awful lot of the time people (including myself) use essentially a ref (by
way of a smart pointer). Often it's due to weak ownership semantics, and
thus iffy design, but it is what it is.
Later,
Brad
More information about the Digitalmars-d
mailing list