Passing a lambda into a function template
<p>I'm learning C++, and I'm trying to implement a binary search function that finds the first element for which a predicate holds. The function's first argument is a vector and the second argument is a function that evaluates the predicate for a given element. The binary search function looks like this:</p>

<pre><code>template &lt;typename T&gt; int binsearch(const std::vector&lt;T&gt; &amp;ts, bool (*predicate)(T)) {
    ...
}
</code></pre>

<p>This works as expected if used like this:</p>

<pre><code>bool gte(int x) {
    return x &gt;= 5;
}

int main(int argc, char** argv) {
    std::vector&lt;int&gt; a = {1, 2, 3};
    binsearch(a, gte);
    return 0;
}
</code></pre>

<p>But if I use a lambda function as a predicate, I get a compiler error: </p>

<pre><code>search-for-a-range.cpp:20:5: error: no matching function for call to 'binsearch'
    binsearch(a, [](int e) -&gt; bool { return e &gt;= 5; });
    ^~~~~~~~~
search-for-a-range.cpp:6:27: note: candidate template ignored: could not match 'bool (*)(T)' against '(lambda at
      search-for-a-range.cpp:20:18)'
template &lt;typename T&gt; int binsearch(const std::vector&lt;T&gt; &amp;ts,
                          ^
1 error generated.
</code></pre>

<p>The above error is generated by</p>

<pre><code>binsearch(a, [](int e) -&gt; bool { return e &gt;= 5; });
</code></pre>

<p>What's wrong? Why is the compiler not convinced that my lambda has the right type?</p>