Partial template type deduction
<p>I am writing a template meant to sort tuples by their elements at compile-time specified indices. I have code that works, but is a pain to use because I have to specify the type of the binary function used to sort the tuple elements.</p>

<pre><code>template &lt;typename BinaryFunction, int Index&gt;
struct sort_by_index_t {
  explicit sort_by_index_t(const BinaryFunction&amp; binary_function)
      : binary_function(binary_function) {}

  template &lt;typename Tuple&gt;
  bool operator()(const Tuple&amp; left, const Tuple&amp; right) const {
    return binary_function(std::get&lt;Index&gt;(left),
                           std::get&lt;Index&gt;(right));
  }

 private:
  const BinaryFunction binary_function;
};

template &lt;typename BinaryFunction, int Index&gt;
sort_by_index_t&lt;BinaryFunction, Index&gt;
sort_by_index(const BinaryFunction&amp; binary_function) {
  return sort_by_index_t&lt;BinaryFunction, Index&gt;(binary_function);
}
</code></pre>

<p>So if I want to sort by the first element in the tuple, I have to type:</p>

<pre><code>sort_by_index&lt;std::less&lt;char&gt;, 0&gt;(std::less&lt;char&gt;());
</code></pre>

<p>Instead, I'd rather have an interface such as the below to avoid duplication, but it does not currently compile.</p>

<pre><code>sort_by_index&lt;0&gt;(std::less&lt;char&gt;());
</code></pre>

<p>I don't see a way to automatically deduce <code>Index</code> (and it would be unnecessary), but <code>sort_by_index</code> should be able to deduce the type of <code>BinaryFunction</code>.</p>

<p>How can I rewrite the above so that I do not need to specify the type of <code>BinaryFunction</code>?</p>