Segmentation fault with std::function and lambda parameters : <p>Can you please explain why this code crashes? I would expect output of "a", but I get segmentation fault.</p>

<pre><code>#include &lt;functional&gt;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;


using namespace std;

struct MyStruct {
  vector&lt;string&gt; a;
  vector&lt;string&gt; b;
};

void out_data(const MyStruct&amp; my_struct, const std::function&lt;const vector&lt;string&gt;&amp;(const MyStruct&amp;)&gt; getter) {
  cout &lt;&lt; getter(my_struct)[0] &lt;&lt; endl;
}

int main(int argc, char** argv)
{
  MyStruct my_struct;
  my_struct.a.push_back("a");
  my_struct.b.push_back("b");
  out_data(my_struct, [](const MyStruct&amp; in) {return in.a;});
  return 0;
}
</code></pre>
