Boost Users :
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-02-20 13:54:18
> boost-users_at_[hidden] spake the secret code
> <019801c8721d$e1612fc0$6407a80a_at_pdimov2> thusly:
>>It is impossible to overload && in such a way so that in e1 && e2, e2 is
>>evaluated when e1 is false. But it's possible to overload f && g so that
>>(f && g)(x) :- f(x) && g(x), g(x) is not evaluated when f(x) is false.
> I guess I'm still a little lost... why does it work for f && g and not
> e1 && e2? Is it because f and g are functors and don't evaluate their
> expressions until their operator() is called?
Yes, exactly. As an example, boost::bind( f, 4 ) creates a function object
that will call f(4) when its operator() is called; and with the operator&&
defined, bind( f, 4 ) && bind( g, 5 ) will call f(4) && g(5) when called,
which will correctly not call g(5) when f(4) returns false.
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