Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and && operator
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2009-06-08 15:12:57


On Mon, Jun 8, 2009 at 2:01 PM, Robert Dailey<rcdailey_at_[hidden]> wrote:
> Hey guys,
> Just wondering what happens if I do this:
> boost::shared_ptr<Foo> foo;
> boost::shared_ptr<Bar> bar;
> if( foo && bar )
> {
>   // Do stuff if both pointers are valid...
> }
> I did not see an overloaded && operator in the interface of the class. When
> using normal pointer semantics, this code is valid through implicit
> conversion of a pointer value to a boolean type.

Since boost::shared_ptr implements the safe_bool idiom, each shared
pointer will use the safe_bool conversion, the result of which will
implicitly convert to a bool. The normal short-circuiting logic should
apply. --DD


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