title: How to conditionally add a function to a class template?
body: <p>I have a Matrix class template as follows:</p>
  
  <pre><code>template&lt;typename T, std::size_t nrows, std::size_t ncols&gt;
  class Matrix
  {
      T data[nrows][ncols];
  public:
      T&amp; operator ()(std::size_t i, std::size_t j)
      {
          return data[i][j];
      }
  };
  </code></pre>
  
  <p>What I want is to define a <code>.setIdentity()</code> function only for instantiations when <code>nrows==ncols</code> is <code>true</code> at compile time. And there will be <strong>no</strong> definition of <code>.setIdentity()</code> when <code>nrows==ncols</code> is <code>false</code>.</p>
  
  <p>What I am trying is using <code>enable_if</code> idiom, but that will define the function for all cases. Isn't it?</p>