Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-12-16 10:42:33


On Monday 16 December 2002 07:05 am, Steven Green wrote:
> >>if (b)
> >>
> >> -- Darin
> >
> >Personally, I use if ( b.get() ), because on at least one compiler (Sun
> > Workshop 5), the simpler syntax caused a compiler error.
>
> I prefer to use if(!!b) because then it will still work if you change
> the pointer type later on in the project and only requires an
> operator!() instead of the more dangerous operator bool (compiler can do
> automatic type conversions behind your back leading to possible bugs if
> you are not careful).
>
> - Steven Green
> http://www.greenius.ltd.uk

FWIW, shared_ptr doesn't actually have an operator bool. It uses the safe_bool
idiom (as do other Boost libraries) to eliminate most automatic type
conversions.

        Doug


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