On Monday, December 26, 2011 20:47:50 Andrei Alexandrescu wrote: > On 12/26/11 11:25 AM, Andrei Alexandrescu wrote: > [snip] > > > Destroy. > > Walter indeed just destroyed me over the phone: I conflated reference > counting with copy-on-write. Essentially instead of defining a reference > type that's garbage-collected, I defined a value type that has cow.
That would explain a few things. ensureUnique is a rather bizarre thing to have just for reference counting. > Which is not bad! Check out the quick fix at http://pastebin.com/HHw06qrc. > > With that, cow is a sheer policy. With the magic of opDispatch it looks > like we can define reference counted containers _and_ value containers - > all in very little code. > > The perspectives here are extremely exciting. The question remains how > to best package this awesome array of options to maximize coherence. So > we have: > > 1. "Basic" containers - reference semantics, using classic garbage > collection > > 2. Reference counted containers - still reference semantics, using > reference counting > > 3. COW containers - value semantics, using reference counting to make > copying O(1). > > How to we provide an Apple-style nice wrapping to all of the above? I'd be inclined to argue that reference counting and COW should be kept separate as opposed to being different versions of the same type simply to make it easier to understand. Not to mention, how often is COW needed for containers? It's useful for many things, but it's only useful for value-type containers, and the use cases for value-type containers are fairly limited I should think. I'm sure that they're very useful under certain circumstances, but as has been pointed out in the past, the fact that C++ defaults to having value-type containers is a big problem. So, I don't think that it's a bad thing to make it possible to have value-type containers and/or COW containers, but if they're going to seriously complicate things, then they should be separate IMHO. They're more specialized as opposed to being the normal use case. By the way, I'm surprised to see the use of delete in that code, since delete is supposed to be going away. - Jonathan M Davis