title: Template class implementing comparison operators
body: <p>It is a frequent task of mine to write all the overloaded comparison operators to a class, so I've written a template class which implements &lt;,&lt;=,>=,!= if the derived class implements == and &lt;. It is working but features a lot of cast and the not that obvious "Curiously recurring template pattern", so I wonder if are there simpler solutions?</p>
  
  <pre><code>template &lt;class Derived&gt;
  class Comparable
  {
  public:
  
      bool operator!=(const Comparable&lt;Derived&gt;&amp; other) {
          return !(static_cast&lt;Derived*&gt;(this)-&gt;operator==
                       (*static_cast&lt;const Derived*&gt;(&amp;other)));
      }
  
      bool operator&lt;=(const Comparable&lt;Derived&gt;&amp; other) {
          return (static_cast&lt;Derived*&gt;(this)-&gt;operator==
                      (*static_cast&lt;const Derived*&gt;(&amp;other)))
                  || (static_cast&lt;Derived*&gt;(this)-&gt;operator&lt;
                      (*static_cast&lt;const Derived*&gt;(&amp;other)));
      }
  
      bool operator&gt;(const Comparable&lt;Derived&gt;&amp; other) {
          return !(static_cast&lt;Derived*&gt;(this)-&gt;operator==
                      (*static_cast&lt;const Derived*&gt;(&amp;other)))
                  &amp;&amp; !(static_cast&lt;Derived*&gt;(this)-&gt;operator&lt;
                      (*static_cast&lt;const Derived*&gt;(&amp;other)));
      }
  
      bool operator&gt;=(const Comparable&lt;Derived&gt;&amp; other) {
          return !(static_cast&lt;Derived*&gt;(this)-&gt;operator&lt;
                      (*static_cast&lt;const Derived*&gt;(&amp;other)));
      }
  };
  </code></pre>