
"Steven Watanabe" <watanabesj@gmail.com> wrote in message news:48178BBA.3050100@providere-consulting.com... [...]
I'm thinking that the cleanest solution will be to have set deletion split the cleanup into first calling all the objects' destructors and then freeing all the memory. When the objects are destroyed you should increment the reference count to make sure that the objects are not destroyed again. When you actually release the memory you can then verify that the reference count is 1, and thus that all references to the object come from within the set.
Otherwise, looking at your current implementation, it looks like shifted_ptr's on the heap will never clean up the object pointed to until the set goes away.
Great news...! I just tried it this way and it works perfectly. The set elements are now following the destruction hierarchy properly which is very nice. I have changed: set::release() and removed U<T>::po_ = 0 in shifted_ptr::release() when an element on the heap is being deleted, which was basically a brute force deletion avoiding recursive problems. But the sequence order doesn't guarantee the element pointed to by po_ will be the first to be deleted. I tried different alternatives and ended with unwanted behaviors so I kept it this way until I work on it again. The library isn't in the Sandbox yet but should be there quickly enough. Bests, -Phil