Is there an Non-Short circuited logical “and” in C++?

前端 未结 7 2154
栀梦
栀梦 2020-12-06 08:49

tl;dr: Is there a non-short circuit logical AND in C++ (similar to &&)?

I\'ve got 2 functions that I want to call, and use the return values to figure out th

7条回答
  •  无人及你
    2020-12-06 09:30

    The & operator performs logical "and" operation for bool operands and is not short circuited.

    It's not a sequence point. You cannot rely on the order of evaluation of the operands. However, it's guaranteed that both operands are evaluated.

    I do not recommend doing this. Using temporary variables is a better solution. Don't sacrifice readability for "clever code".

提交回复
热议问题