title: Couldn't deduce template parameter from function parameter's default argument
body: <p>I'm trying to make a function which finds the minimum element in a range which satisfies a given condition:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  template &lt;typename It, typename Pred, typename Comp&gt;
  It minElementWhere(
      It begin,
      It end,
      Pred pred = Pred(),
  
      // Use less-than as the default comparator.
      Comp comp = std::less&lt;decltype(*std::declval&lt;It&gt;())&gt;()
  ) {
      It minElement = end;
  
      for (It it = begin; it != end; ++it) {
          if (!pred(*it)) {
              continue;
          }
  
          if (comp(*it, *minElement)) {
              minElement = it;
          }
      }
  
      return minElement;
  }
  
  int main() {
      std::vector&lt;double&gt; foo;
      foo.push_back(6);
      foo.push_back(10);
      foo.push_back(-3);
      foo.push_back(7);
  
      std::cout &lt;&lt; *minElementWhere(
          foo.begin(),
          foo.end(),
          [](double val) {
              return val &gt;= 0;
          }
      ) &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>But I get this error:</p>
  
  <pre><code>main.cpp: In function 'int main()':
  main.cpp:40:5: error: no matching function for call to 'minElementWhere(std::vector&lt;double&gt;::iterator, std::vector&lt;double&gt;::iterator, main()::__lambda0)'
       ) &lt;&lt; std::endl;
       ^
  main.cpp:40:5: note: candidate is:
  main.cpp:6:4: note: template&lt;class It, class Pred, class Comp&gt; It minElementWhere(It, It, Pred, Comp)
   It minElementWhere(
      ^
  main.cpp:6:4: note:   template argument deduction/substitution failed:
  main.cpp:40:5: note:   couldn't deduce template parameter 'Comp'
       ) &lt;&lt; std::endl;
  </code></pre>
  
  <p><code>Comp</code> isn't the return type, so it's not trying to deduce the return type, and it doesn't seem to me like there are ambiguous overloads of <code>Comp</code> (since there can only be one return type of dereferencing an <code>It</code>). Why am I getting this error, and how can I fix it?</p>