Handles to objects in central registry with automated cleanup
<p>I have a central repository of objects <code>Base</code> which can produce various things. <code>Base</code> must keep a pointer to all objects, as a central update method has to iterate through all objects created by the <code>Base</code> instance. However, if the last handle to an object is destroyed, there is no need to keep it around any more so <code>Base</code> should get somehow informed that it is ok to delete the object now. Manual deletion of objects should be also possible, which would immediately invalidate all handles. Some code to clarify:</p>

<pre><code>Base* b = new Base;
auto h0 = b-&gt;MakeFoo ();
auto h1 = h0;
b-&gt;Delete (h0);
// h1 is invalid here
{
  auto h2 = b-&gt;MakeFoo ();
}
// Base::Delete (h2) was called, as the last reference to it died
// shared_ptr/weak_ptr won't work here, as there would be still one
// reference in Base
auto h3 = b-&gt;MakeFoo ();
delete b;
// h3 is invalid here, hence shared_ptr is not enough
// weak_ptr would work here
</code></pre>

<p>Anything ready-to-use out there that I can adopt for this? Performance does not matter too much in this case.</p>
