[Lumiera] GUI boost::shared_pointer to std::tr1

Michael R Fisher mfisher31 at gmail.com
Fri Oct 21 16:03:52 CEST 2011

Haha, I just realized that enable_shared_from_this is indeed included in std::tr1,  It was late when I was finishing up and didn't see it.  Will fix that after my coffee is ready.

Herman, I'll be around as usual.  Hope to see you on IRC.

> Based on my own experience, using enable_shared_from_this is almost
> never a good idea. Because basically this is a sign that something
> in the design is not quite right.
> When we deal with shared-ptrs, actually the topic in question is
> ownership. We could well cheat our way around that topic, but
> IMHO this should be taken rather seriously.
> The owner of an object is responsible for two things:
> - creating and destroying the object
> - providing access for other client code, but denying
>    access when the object is already destroyed.
> Basically, this approach turns an involved low-level trickery
> into a clean service, which is either available or fails gracefully.
> Thus, if there is the necessity for shared_from_this, we can conclude
> that ownership wasn't clarified and settled. Someone did create the
> object in question, and then didn't care further, but just let it
> go. Or someone else bypassed the ownership/management layer and
> just stashed away a plain pointer.
> Both could be a recipe for disaster.
> So I think we should rather try to understand why anyone would use
> a direct pointer or reference to ParentTrack.
> Ideally, an object should be always created by
> shared_ptr<MyObject>  newThingie (new MyObject(some,parameters));
> This ensures that
> - either the ctor of the object throws right away
> - or the object, once created, is immediately handed over to the
>    shared_ptr "newThingie", which cares for management.
> Now, according to my experience, very often you encounter a situation
> where you want to "return *this". Again, you shouldnt. This is again
> a sign that the responsibility/ownership/dependencies aren't settled.
> OK -- having said that...
> Right now I'll have to leave and do a visit. Later this evening maybe
> we might meet on IRC and look into the details how to refactor that.
> Cheers,
> Hermann
> PS: there is a reason why enable_shared_from_this wasn't accepted into
> the standard. If I recall correct, there were discussions and several
> participants argued along the same lines as I did above. Please
> feel free to contradict, correct me, point out better solutions!
> I am all interested in this kind of discussions, as they help
> understanding better what we're doing
> _______________________________________________
> Lumiera mailing list
> Lumiera at lists.lumiera.org
> http://lists.lumiera.org/cgi-bin/mailman/listinfo/lumiera
> http://lumiera.org/donations.html

More information about the Lumiera mailing list