title: Short-circuit evaluation and assignment in C++
body: <p>Is something like this possible in C++:</p>
  
  <pre><code>if (int* x = (foo() || bar()))
  {
      // do something with x
  }
  else
  {
      // do something else if both foo() and bar() return nullptr
  }
  </code></pre>
  
  <p>I know the code will not compile (cannot convert bool to int*), but is there a valid equivalent "shortcut" code to be able to do this kind of shortcut? Basically, what I want is to assign to x the return value of foo() if foo() does not return a null pointer. If foo() yields a null pointer, then assign the return value of bar() to x.</p>
  
  <p>Assume that foo() and bar() are expensive calculations, so need to minimize the number of calls to them. If foo() does not yield a null pointer, then ideally, there should be no need to call bar().</p>