title: How properly pass comparator to another template function
body: <p>I need a function that will take two iterators and a custom comparator to compare values of this iterators. I don't want use additional template argument for this. I've implemented it in this way:</p>
  
  <pre><code>template&lt;typename T&gt;
  void foo(T begin, T end,
    function&lt;bool(decltype(*begin), decltype(*begin))&gt; compare = less&lt;decltype(*begin)&gt;())
  {
      // I want to use 'compare' as: "compare(*begin, *begin);"
  }
  </code></pre>
  
  <p>This code has been compiled normally by clang, but on GCC 5.4.0 I've got some errors:</p>
  
  <pre><code>binary_heap.cpp:10:79: error: local variable 'begin' may not appear in this context
     function&lt;bool(decltype(*begin), decltype(*begin))&gt; compare = less&lt;decltype(*begin)&gt;())
                                                                                 ^
  binary_heap.cpp:10:85: error: template argument 1 is invalid
     function&lt;bool(decltype(*begin), decltype(*begin))&gt; compare = less&lt;decltype(*begin)&gt;())
  </code></pre>
  
  <p>How to correct this code so that it can be successfully compiled on both clang and GCC? Or maybe are there a more suitable solution for defining such function?</p>