Some operators such as &&
and ||
perform short-circuit evaluation. Also, when a function is called with arguments, all arguments are constructed before calling the function.
For instance, take the following three functions
bool f1();
bool f2();
bool f3(bool, bool);
if I call
if( f3(f2(),f1()) )//Do something
Then the return value of both f2
and f1
are evaluated before f3
is called. But, if I had used (the regular) operator||
instead of f3
, than the code above would be equivalent to
if( f2()||f1() )//Do something
and f1
won't be evaluated if f2
evaluates to true.
My question is: is it possible to have f3
(a user defined function taking two booleans) behave the same way? If not, what makes the operator||
so special?