title: Should std::sort work with lambda function in c++0x/c++11?
body: <p>I tried to use lambda function with <code>sort</code>, but was getting "Segmentation fault" errors. I managed to simplify the code to the following:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  int main()
  {
    const int len = 18;
    int intArr[len];
    for (int i=0;i&lt;len;i++) intArr[i]=1000+i;
    // The following is expected to sort all but the last element of the array
    std::sort(intArr, intArr + len -1, [](int a, int b)
      {
        std::cout&lt;&lt;"("&lt;&lt;a&lt;&lt;", "&lt;&lt;b&lt;&lt;")\n";
        return (a&lt;b?-1:(a&gt;b?1:0));
      });
    return 0;
  }
  </code></pre>
  
  <p>I compile and run this code in Ubuntu 11.04 (x64) using</p>
  
  <p><code>g++ -std=gnu++0x test2.cpp &amp;&amp; ./a.out</code>.</p>
  
  <p>It prints a lot of pairs of the form (large_integer, 1008), a couple of (0, 1008) and exits with "Segmentation fault".</p>