title: In continuation of my attempts to understand std::enable_if usage
body: <p>In this piece of code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;type_traits&gt;
  #include &lt;ios&gt;
  
  using std::enable_if;
  using std::is_same;
  using std::boolalpha;
  using std::cout;
  using std::endl;
  
  template &lt;typename T&gt;
  struct S {
    S(): t(static_cast&lt;T&gt;(NULL)) { }
  
    // void type() {
    //   cout &lt;&lt; boolalpha;
    //   cout &lt;&lt; is_same&lt;T,int&gt;::value &lt;&lt; endl;
    // }
  
    template &lt;typename enable_if&lt;is_same&lt;T,int&gt;::value,T&gt;::type&gt;
    void type() {
      cout &lt;&lt; boolalpha &lt;&lt; true &lt;&lt; endl;
    }
  
    T t;
  };
  
  int main(){
    S&lt;int&gt; s;
    s.type();
    return(0);
  }
  </code></pre>
  
  <p>I get successful compilation and output for the method <code>type()</code> implemented as a non-template function; however, for the same method implemented as a template function using <code>std::enable_if</code> I get the following compilation error:</p>
  
  <pre><code>so_main.cpp:23:11: error: no matching member function for call to 'type'
          s.type();
          ~~^~~~
  so_main.cpp:15:73: note: candidate template ignored: couldn't infer template argument ''
          template&lt;typename enable_if&lt;is_same&lt;T,int&gt;::value,T&gt;::type&gt;void type(){cout &lt;&lt; boolalpha &lt;&lt; true &lt;&lt; endl;}
                                                                          ^
  1 error generated.
  </code></pre>
  
  <p>My understanding is that the logic implemented in both cases is similar.
  When the method is non-template, the type for <code>T</code> is corroborated as <code>int</code>. However, when <code>std::enable_if</code> is used to enable the template function for the same condition (i.e., <code>T</code> is <code>int</code>), the code does not compile.</p>