title: c++11 sorting list using lambda
body: <p>While practicing the use of lambdas, I wrote this program which is supposed to sort a <code>list</code> of <code>pair</code>s by their second element (an <code>int</code>).</p>
  <pre>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;list&gt;
  
  using namespace std;
  int main()
  {
      list&lt;pair &lt;string, int&gt;&gt; s = {{&quot;two&quot;, 2}, {&quot;one&quot;, 1}, {&quot;three&quot;, 3}};
  
      sort(s.begin(), s.end(), [](pair&lt;string,int&gt; a, pair&lt;string, int&gt; b) -&gt; bool {
          return (a.second) &gt; (b.second);
      });
  
      for_each(s.begin(), s.end(), [](pair&lt;string, int&gt; a) {
          cout &lt;&lt; a.first &lt;&lt; &quot; &quot; &lt;&lt; a.second &lt;&lt; endl;
      });
  }
  </pre>
  <p>I get those errors, though:</p>
  <pre><code>c:\qt\qt5.2.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\stl_algo.h:5513: error: no match for 'operator-' (operand types are 'std::_List_iterator&lt;std::pair&lt;std::basic_string&lt;char&gt;, int&gt; &gt;' and 'std::_List_iterator&lt;std::pair&lt;std::basic_string&lt;char&gt;, int&gt; &gt;')
       std::__lg(__last - __first) * 2, __comp);
                    ^
  
  c:\qt\qt5.2.0\tools\mingw48_32\lib\gcc\i686-w64-mingw32\4.8.0\include\c++\bits\stl_algo.h:2245: ошибка: 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator&lt;std::pair&lt;std::basic_string&lt;char&gt;, int&gt; &gt;; _Compare = main()::__lambda0]', declared using local type 'main()::__lambda0', is used but never defined [-fpermissive]
       __final_insertion_sort(_RandomAccessIterator __first,
       ^
  </code></pre>
  <p>What is wrong with my code?</p>