title: How can pointers be totally ordered?
body: <p>Pointers in C++ may in general only be compared for equality. By contrast, less-than comparison is only allowed for two pointers that point to subobjects of the same complete object (e.g. array elements).</p>
  
  <p>So given <code>T * p, * q</code>, it is illegal in general to evaluate <code>p &lt; q</code>.</p>
  
  <p>The standard library contains functor class templates <code>std::less&lt;T&gt;</code> etc. which wrap the built-in operator <code>&lt;</code>. However, the standard has this to say about pointer types (20.8.5/8):</p>
  
  <blockquote>
    <p>For templates <code>greater</code>, <code>less</code>, <code>greater_equal</code>, and <code>less_equal</code>, the specializations for any pointer type yield a total order, even if the built-in operators <code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, <code>&gt;=</code> do not.</p>
  </blockquote>
  
  <p>How can this be realised? Is it even possible to implement this?</p>
  
  <p>I took a look at GCC 4.7.2 and Clang 3.2, which don't contain <em>any</em> specialization for pointer types at all. They seem to depend on <code>&lt;</code> being valid unconditionally on all their supported platforms.</p>