|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-29 14:21:16
"wasekvesely <vaclav.vesely_at_[hidden]>" <vaclav.vesely_at_[hidden]> writes:
> Hi,
>
> I've found this in "shared_ptr.hpp":
>
> // implicit conversion to "bool"
> typedef T * (this_type::*unspecified_bool_type)() const;
>
> operator unspecified_bool_type() const // never throws
> { return px == 0? 0: &this_type::get; }
>
> Why this is better than:
>
> operator bool() const
> { return px != 0; }
>
> What more can I do with somethin like this?
It's not that you can do more; quite the opposite.
int f(long);
int x = f(shared_ptr<int>()); // error
With operator bool(), that (and many other abuses) would compile.
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
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