Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and && operator
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-06-08 23:27:20


On Mon, Jun 8, 2009 at 6:19 PM, Kenny Riddile <kfriddile_at_[hidden]> wrote:

> Robert Dailey wrote:
>
>> On Mon, Jun 8, 2009 at 2:16 PM, Steven Watanabe <watanabesj_at_[hidden]<mailto:
>> watanabesj_at_[hidden]>> wrote:
>>
>> AMDG
>>
>>
>> Robert Dailey wrote:
>>
>> 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.
>>
>>
>> The same applies to shared_ptr.
>> http://www.boost.org/libs/smart_ptr/shared_ptr.htm#conversions
>>
>>
>> Thanks. I figured this was the case but I guess I was just having trouble
>> finding the header file in which this casting operator is implemented. I
>> appreciate the answers to my embarrassingly obvious question.
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
> Here's a short explanation why you won't find operators && or || overloaded
> very often:
>
> http://blog.emptycrate.com/node/363
>
> For a more thorough explanation, see chapter 7 in More Effective C++.

Thanks Kenny, I'm already aware of this though. The reason why I ask is
because I have to work on a code base that insists on overloading such
operators, and I'm investigating ways of cleaning it up. The code in
question has no regard for short circuiting since they are already using
overloaded && and || semantics.

I appreciate everyone's help.



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