Boost logo

Boost Users :

From: Alex MDC (alex.mdc_at_[hidden])
Date: 2008-05-13 08:47:21


Hi James,

Unfortunately it is not possible to emulating the short-circuiting behavour
of the inbuilt && and || operators, as both sides are just arguments to a
function disguised as an operator.

However I do agree that this behaviour is unexpected to say the least, and
terrible for other people looking at the code without knowing they aren't
native booleans (and expecting short-circuiting operators). However it is
hard to consider an alternative syntax which makes tribools looks anything
like native booleans...

BTW, this is the very reason why Meyers (in More Effective C++) says to
never overload boolean operators!

Alex

2008/5/13 Jean-Pierre Bergamin <james_at_[hidden]>:

> Hello boost-users
>
> I just ran into quite a bad issue with boost::tribool. The overloaded
> operators && and || may (and normally do) evaluate the righthand side of
> logical expressions although not needed/permitted. They i.e. evaluate the
> rhs expression in a conjunction where the first term is false.
>
> This leads of course to very surprising results. IMHO, the provided
> operators should be removed or should honor normal semantics.
> Shall I issue a bug-report? I think the current situation is quite
> unconvincingly.
>
>
> Regards
>
> James
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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