title: C++ Custom Comparison Function with Template as Function Parameter
body: <p>I'm trying to implement/use a comparator style interface like the one you would find in Java that would allow me to pass a generic comparator type to a function and use that to sort a data set.</p>
  
  <p>This is because I need a variety of different comparison functions and I want be able to pass the one I need into the sort function.</p>
  
  <p>Here's a code snippet of what I have so far and hopefully you can tell what I mean:</p>
  
  <pre><code>void Population::sort(const std::shared_ptr&lt;Comparator&lt;Solution&gt;&gt;&amp; comparator)
  {
      std::sort(data.begin(), data.end(), comparator.get());
  }
  </code></pre>
  
  <p>And the comparator interface I've tried to implement</p>
  
  <pre><code>template &lt;typename T&gt; class Comparator : public std::binary_function&lt;T,T,bool&gt;
  {
  public:
      virtual ~Comparator ();
      virtual bool operator() ( const T &amp;o1, const T &amp;o2  ) = 0;
  };
  </code></pre>
  
  <p>It's probably something obvious I'm doing wrong as I don't know a whole lot of C++.</p>
  
  <p>Cheers!</p>