Boost logo

Boost :

From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2008-05-21 12:28:37


Jim wrote:
>Wouldn't it make more sense to use operator| instead of operator|| ?
>When used in the context of boolean algebra, the former always carries
>with it the expectation that there will be no short-circuiting. The
>lack of short-circuiting makes overloading operator|| a headache for
>users (though I can't imagine how you'd implement it to allow
>short-circuiting).

I'm going to agree with Jim here. The bitwise operators are a better
choice for overloading than the logical, which imply flow control. I
also agree with him that short-circuiting can't be implemented. If you
have expression templates as someone else suggested you could short
circuit evaluating your own expressions, but not short circuit
evaluating other code, only the compiler can do that:

A || B || foo(C);

The compiler won't even look at your || operator until after it has
called foo. You must evaluate foo before you construct your expression
template, and you could short circuit looking at its result if A or B
were true, but you couldn't prevent it from being called on C in the
first place.

Luke


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk