Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-27 05:55:12


From: "Alan M. Carroll" <yg-boost-users_at_[hidden]>
> > 5.3.5/2 (ISO): "[Note: a pointer to a const type can be the operand of a
> > delete-expression; ...]"
>
> So, you agree that "delete ptr" is not a problem for the cast to (void
const
> *)?

No, I don't. Deleting a void const * is not (directly) prohibited by the
standard, and some compilers let it through without even a warning.

> > That aside, do you really have code that depends on a specific
conversion
> to
> > void const *?
>
> Not directly. This issue came up with earlier version of Boost smart_ptr
> that didn't have the methods necessary for things like
> if (ptr) { /* stuff */ }

This is now supported.

> The conversion provides this. It also supports the idiom
> if (ptr == 0) { /* stuff */ }
> which I believe is not possible with the current Boost smart_ptr. I've
also
> had issues with comparisons between shared_ptr<T> and T*. While this can
be
> avoided through minor changes of habit, it is much easier for me to
overcome
> the resistance of fellow programmers if they can literally drop in
> shared_ptr<T> instead of T* and constructs such as the above occur
> frequently enough to be an issue.

OK, but you are arguing for shared_ptr<T> to T* comparisons, not for a void
const * conversion. The right way to support these comparisons is by
defining the appropriate operators. If you want to "lobby" for shared_ptr<T>
== T*, please do so on the developer list, I've no problem with that. :-) In
my opinion this is a "neutral" feature, i.e. the pros and cons balance
themselves. A smart pointer is different enough from T* so it sometimes even
helps to _not_ make it a drop-in replacement and prefer the more explicit
p.get() == q for mixed comparisons.

The if(p) syntax supports the important idiom:

if(shared_ptr<T> p = make_shared(q))
{
// ...
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net