title: lvalue reference became invalid after passing through an identity function
body: <p>Would someone explain why the reference became invalid after going through an "identity" function, <code>foo1</code>?  Isn't an "address" to <code>A</code> is passed into and returned by <code>foo1</code>?</p>
  
  <pre><code>struct A {
      A(int x) : x_(x) {}
      int x_;
  };
  
  int main() {
  
      function&lt;const A&amp;(const A&amp; r)&gt; foo1 = [](const A&amp; r) { 
          return r;
      };
  
      vector&lt;A&gt; vec{1, 2, 3};
      cout &lt;&lt; foo1(vec[0]).x_ &lt;&lt; endl;   // RUNTIME ERROR
  
      return 0;
  }
  </code></pre>
  
  <p>How does the problem line differ from:</p>
  
  <pre><code>const A&amp; r = vec[0];
  const A&amp; r1 = r;
  </code></pre>