title: Template compare operator
body: <p>I have a following template class:</p>
  
  <pre><code>template&lt;int size, typename Type&gt;
  class Matrix {
      public:
          Matrix();
          ...
          Type operator ()(int row, int column) {...}
      private:
          std::array&lt;Type, size*size&gt; _array;
  }
  </code></pre>
  
  <p>And I want to overload <code>equal to</code> comparison operator to compare <code>Matrix</code> objects:</p>
  
  <pre><code>template &lt;int size, typename LeftType, typename RightType&gt;
  bool operator ==(const Matrix&lt;size, LeftType&gt; &amp; left, const Matrix&lt;size, RightType&gt; &amp; right) {
      for (int i = 0; i &lt; size; ++i) {
          for (int j = 0; j &lt; size; ++j) {
              ...
          }
      }
  }
  </code></pre>
  
  <p>The problem is that comparison of integer types and real types is quite different:</p>
  
  <p><code>real case</code>:</p>
  
  <pre><code>template &lt;int size, typename LeftType, typename RightType&gt;
  bool operator ==(const Matrix&lt;size, LeftType&gt; &amp; left, const Matrix&lt;size, RightType&gt; &amp; right) {
      for (int i = 0; i &lt; size; ++i) {
          for (int j = 0; j &lt; size; ++j) {
              if (qFuzzyIsNull(left(i, j)) || qFuzzyIsNull(right(i, j))) {
                  if (!qFuzzyCompare(left(i, j) + 1, right(i, j) + 1)) {
                      return false;
                  }
              } else {
                  if (!qFuzzyCompare(left(i, j), right(i, j))) {
                      return false;
                  }
              }
          }
      }
      return true;
  }
  </code></pre>
  
  <p>(I'm using Qt's <a href="http://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare" rel="nofollow noreferrer">qFuzzyCompare</a> and <a href="http://doc.qt.io/qt-5/qtglobal.html#qFuzzyIsNull" rel="nofollow noreferrer">qFuzzyIsNull</a>)</p>
  
  <p><code>integer case</code>:</p>
  
  <pre><code>template &lt;int size, typename LeftType, typename RightType&gt;
  bool operator ==(const Matrix&lt;size, LeftType&gt; &amp; left, const Matrix&lt;size, RightType&gt; &amp; right) {
      for (int i = 0; i &lt; size; ++i) {
          for (int j = 0; j &lt; size; ++j) {
              if (left(i, j) != right(i, j)) {
                  return false;
              }
          }
      }
      return true;
  }
  </code></pre>
  
  <p>How to enable <code>integer case</code> if both <code>LeftType</code> and <code>RightType</code> integer and enable <code>real case</code> if at least one <code>LeftType</code> or <code>RightType</code> is real?</p>