<?xml version="1.0"?>
<clause number="14.11.2" title="User-defined conditional logical operators">
  <paragraph>When the operands of &amp;&amp; or || are of types that declare an applicable user-defined operator &amp; or operator |, both of the following must be true, where T is the type in which the selected operator is declared: <list><list_item> The return type and the type of each parameter of the selected operator must be T. In other words, the operator must compute the logical AND or the logical OR of two operands of type T, and must return a result of type T. </list_item><list_item> T must contain declarations of operator true and operator false. </list_item></list></paragraph>
  <paragraph>A compile-time error occurs if either of these requirements is not satisfied. Otherwise, the &amp;&amp; or || operation is evaluated by combining the user-defined operator true or operator false with the selected user-defined operator: <list><list_item> The operation x &amp;&amp; y is evaluated as T.false(x) ? x : T.&amp;(x, y), where T.false(x) is an invocation of the operator false declared in T, and T.&amp;(x, y) is an invocation of the selected operator &amp;. In other words, x is first evaluated and operator false is invoked on the result to determine if x is definitely false. Then, if x is definitely false, the result of the operation is the value previously computed for x. Otherwise, y is evaluated, and the selected operator &amp; is invoked on the value previously computed for x and the value computed for y to produce the result of the operation. </list_item><list_item> The operation x || y is evaluated as T.true(x) ? x : T.|(x, y), where T.true(x) is an invocation of the operator true declared in T, and T.|(x, y) is an invocation of the selected operator |. In other words, x is first evaluated and operator true is invoked on the result to determine if x is definitely true. Then, if x is definitely true, the result of the operation is the value previously computed for x. Otherwise, y is evaluated, and the selected operator | is invoked on the value previously computed for x and the value computed for y to produce the result of the operation. </list_item></list></paragraph>
  <paragraph>In either of these operations, the expression given by x is only evaluated once, and the expression given by y is either not evaluated or evaluated exactly once. </paragraph>
  <paragraph>For an example of a type that implements operator true and operator false, see <hyperlink>18.4.2</hyperlink>. </paragraph>
</clause>
