title: C++ 11 binary_search and lambda function use case
body: <p>I would like to use std::binary_search with lambda function but got compiling error. </p>
  
  <p>Suppose I have a matrix, with the first column sorted.</p>
  
  <pre><code>1  5  9
  2  4  6 
  3  7  8
  
  vector&lt;vector&lt;int&gt;&gt; matrix;
  matrix.push_back(vector&lt;int&gt; {1, 5, 9)};
  matrix.push_back(vector&lt;int&gt; {2, 4, 6)};
  matrix.push_back(vector&lt;int&gt; {3, 7, 8)};
  </code></pre>
  
  <p>I want to search  whether a number exists in the first column.</p>
  
  <p>(Please please don't consider the real usage of this for a moment)</p>
  
  <p>And I have tried:</p>
  
  <p>Version 1:</p>
  
  <pre><code>binary_search(begin(matrix), end(matrix), 2,
    [] (const vector&lt;int&gt; &amp;r1, const vector&lt;int&gt; &amp;r2) {return r1[0] &lt; r2[0];});
  </code></pre>
  
  <p>Version 2:</p>
  
  <pre><code>binary_search(begin(matrix), end(matrix), vector&lt;int&gt; {2},
    [] (const vector&lt;int&gt; &amp;r1, const vector&lt;int&gt; &amp;r2) {return r1[0] &lt; r2[0];});
  </code></pre>
  
  <p>Could any one help with me how to make it work ? (binary_search in the first column of a matrix)</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>Thank you everyone! I learnt a lesson that I should put the original code that caused the bug here. </p>
  
  <p>At last, I found out that it is because I didn't put <strong>const</strong> in lambda function that caused the problem. I will close this post soon. Thanks everyone again!</p>