title: How do I turn relational comparison of pointers into an error?
body: <p>We've been bitten by the following bug many times:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  void print(int* pn) { cout &lt;&lt; *pn &lt;&lt; " "; }
  
  int main() {
      int* n1 = new int(1);
      int* n2 = new int(2);
      int* n3 = new int(3);
  
      vector&lt;int*&gt; v;
      v.push_back(n1);
      v.push_back(n2);
      v.push_back(n3);
  
      sort(v.begin(), v.end());   // Here be dragons!
  
      for_each(v.begin(), v.end(), print);
      cout &lt;&lt; endl;
      delete n1; delete n2; delete n3;
  }
  </code></pre>
  
  <p>The problem is that std::sort is comparing integer pointers not integers, which is not what the programmer intended.  Worse, the output may appear correct and deterministic (consider the order of addresses returned by new or allocated on the stack).  The root problem is that sort eventually calls operator&lt; for T, which is rarely a good idea when T is a pointer type.  </p>
  
  <p>Is there any way to prevent this or at least get a compiler warning?  For example, is there a way to create a custom version of std::sort that <em>requires</em> a comparison function when T is a pointer?</p>