Boost logo

Boost Users :

From: Marshall Clow (marshall_at_[hidden])
Date: 2008-02-14 14:44:04


At 8:12 PM +0100 2/14/08, Jean-Pierre Bergamin wrote:
>Hello everyone
>
>Is there a reason why boost::bind does not overload the logical operators ||
>and &&? They definitively would come in more handy to build up complicated
>logical expressions than using the std::logical_and and std::logical_or
>function objects.

My guess is that since boost::bind could not replicate the behavior
of && and ||, the authors decided not to provide them.

The built in && will not evaluate the second argument if the first is false.
Similarly, the built in || will not evalulate the second argument if
the first is true.

You can write
        if ( p != NULL && p->someField == 3 )
confident in the knowledge that "p->someField" will not be read from
if p == NULL.

-- 
-- Marshall
Marshall Clow     Idio Software   <mailto:marshall_at_[hidden]>
It is by caffeine alone I set my mind in motion.
It is by the beans of Java that thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.

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