The lambda return type in C++
<blockquote>
  <p>Lambda with function bodies that contain anything other than a single
  return statement that do not specify a return type return void.   </p>
  
  <p>via 《C++ Primer》 5th Edition, Page 389.</p>
  
  <p>However, if we write the seemingly equivalent program using an if
  statement, our code won't compile:</p>

<pre><code>//error: can't deduce the return type for the lambda.

transform(vi.begin(), vi.end(), vi.begin(), [](int i) { if(i &lt; 0) return -i; else return i; } );
</code></pre>
  
  <p>via 《C++ Primer》 5th Edition, Page 396.</p>
</blockquote>

<p>I write a program in Visual Studio:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;
using namespace std;

int main(void) {
    vector&lt;int&gt; vi{ 1, -2, 3, -4, 5, -6 };
    /* Is the return type void？ */
    transform(vi.begin(), vi.end(), vi.begin(), [](int i) {
                                                    if (i &lt; 0) return -i;
                                                    else return i; });

    for (int i : vi)
        cout &lt;&lt; i &lt;&lt; " ";
    cout &lt;&lt; endl;

    system("pause");
    return 0;
}
</code></pre>

<p>But it can correctly run.</p>

<p>And then, I add some statements in Visual Studio:</p>

<pre><code>auto f = [](int i) {
                    if (i &lt; 0) return -i;
                    else return i; };
</code></pre>

<p>As I move the cursor to the f, it shows me that the f's return type is int.</p>

<p>Why is this?</p>

<p>I am confused.</p>