User overloaded logical operators in C++ ( &&, ||
) behave like regular functions. That is, both arguments in bool operator&&(const T &a, const T2 &b);
are evaluated before entering the function, as entering a function is a sequence point[1] in C++. All good up to here.
Now, “builtin operators && and || perform short-circuit evaluation” [2][3], where there is a sequence point between the left and right sides. The cited reference isn’t clear what “builtin” are, only that they take bool
operands, or convert them using “contextual conversion to bool”. It also mentions that only “two standard library classes overload these operators [because] the short-circuiting properties (...) do not apply to overloads, and because types with boolean semantics are uncommon.” [2]
Types with boolean semantics? How exactly do “builtin operators” work? Is it simply impossible to define logical operators with short-circuit evaluation?
[1] https://en.wikipedia.org/wiki/Sequence_point
[2] http://en.cppreference.com/w/cpp/language/operator_logical