Boost logo

Boost :

From: AlisdairM (AlisdairM_at_[hidden])
Date: 2001-09-01 04:04:37


First a call for help, how do I get MS Outlook newsreader to use a sensible
quoting style? I can't reply point-by-point without losing my response in
the original message.

In response to David

First issue: Agree! While I believe both scoped_ptr and shared_ptr are
vital classes to submit for standardisation, as they cover over 90% of my
smart pointer requirements, an advanced policy-based smart pointer would be
extremely useful for the other 10% of cases. I feel it is important to
retain scoped/shared_pointer though for the much simpler usage in the
majority of cases.

Second issue: Makes sense, but if all I see in the code is an assert with
minor comment, I can imagine forgetting the issue in six months time and
trying to work out what is going on again. Needs a comment in the
documentation, or a small FAQ entry. After all, it is NOT self-assignment
that is the error (that is safely handled), but the fact that you are
self-assigning means you risk using reset with other pointers which you
cannot catch, and is not indicated clearly by asserting self-assignment!

AlisdairM

-----Original Message-----
From: David Abrahams [mailto:david.abrahams_at_[hidden]]
Sent: 30 August 2001 19:27
To: Boost_at_Yahoogroups. Com
Cc: Andrei Alexandrescu
Subject: [boost] shared_xxx issues

First Issue:

I've just found myself wanting a really flexible smart pointer, along the
lines of the one in Loki by Andrei Alexandrescu. For a long time I thought
that I would rarely want more than shared_ptr, but I can see that this is
going to come up again and again for me. Unfortunately, I couldn't use
Andrei's design because very few compilers will apply the empty base
optimization in cases of multiple inheritance. So, even if shared_ptr is our
choice for submission to the committee I would really like to see a
policy-based smart pointer in boost.

Second Issue:

I found the following code in shared_array (and I assume the analogous code
is in shared_ptr):

        void reset(T* p=0)
        {
            if ( px == p ) return; // fix: self-assignment safe

What this does is to make a silent success of resetting a shared_ptr with
the pointer it owns. The problem with that is that resetting a shared_ptr to
any /other/ pointer which is managed by a shared_ptr is a fatal (and
hard-to-detect) error, which happens even to experienced programmers. I
don't think the trade-off is a good one. Making this special case (which we
can detect) silently work when all other cases will fail without complaint
is a mistake. I'd rather see an assert() here.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk