On 14.12.2010 20:53, Andrei Alexandrescu wrote:
Coming from an STL background I was also very comfortable with the
notion of value. Walter pointed to me that in the STL what you worry
about most of the time is to _undo_ the propensity of objects getting
copied at the drop of a hat. For example, think of the common n00b
error of passing containers by value.

True thing, C++/STL does much work to prevent the copy-mechanism, but it can be circumvented by using the indirection+refCount trick. Than it doesnt matter how you pass it, it gets copied layzily when the first actual change occurs. That places some overhead
1) increasing/decrasing refcount on every argument-passing
2) checking for refCount>1 on every modifying method-call (not on the reading methods)

I'm pretty sure (1) is insignificand. (2) I'm not sure about. For a very simple list-container it might be a problem, but for sophisticated structures like hashtables or trees this one check is probably insignificand.


So since we have the opportunity to decide now for eternity the right
thing, I think reference semantics works great with containers.

Indeed. Whichever way to go, you need a good reason. I hope, a similar discussion will be placed for the actual interface of the container-lib. (Which template-params should there be? T, Allocator, Comp are the three most classic ones, but more or less is possible, and what kinds of containers should be there at all?. Anyway, doesnt belong here now).

Krox

Reply via email to