title: c++: Multiple assignment inside if block syntax for short circuiting
body: <p>I wanted to be able to do multiple assignments in an if block and short-circuit if the first one fails. However, this does not compile and says, <code>expected primary-expression before ‘auto’</code></p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;optional&gt;
  
  std::optional&lt;int&gt; foo()
  {
      return 0;
  }
  
  int main() {
      if (auto a = foo() &amp;&amp; auto b = foo())
      {
          std::cout &lt;&lt; "a = " &lt;&lt; *a &lt;&lt; ", b = " &lt;&lt; *b &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>The following works though and does what I want. </p>
  
  <pre class="lang-cpp prettyprint-override"><code>    if (auto a = foo())
      {
        if (auto b = foo()) {
          std::cout &lt;&lt; "a = " &lt;&lt; *a &lt;&lt; ", b = " &lt;&lt; *b &lt;&lt; std::endl;
        }
      }
  </code></pre>
  
  <p>But is there a way for me to use the syntax in the first one? Using parenthesis to surround the expressions does not work.</p>