title: how to use boost::enable_if in class template
body: <p>I am trying to use the boost::enable_if to turn on/off some functions in the class template but always get the compilation error <strong>error: no type named "type" in struct boost::enable_if</strong>.</p>
  
  <p>My snippet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;tr1/type_traits&gt;
  #include &lt;boost/utility.hpp&gt;
  
  namespace std {
      using namespace tr1;
  }
  
  template &lt;typename T1&gt;
  struct C {
      template&lt; typename T2 &gt;
      void test( T2&amp;, typename boost::enable_if&lt;
      std::is_const&lt; T1 &gt;, T1 &gt;::type* = 0 ) {
  
          std::cout &lt;&lt; "const" &lt;&lt; std::endl;
      }
  
      template&lt; typename T2 &gt;
      void test( T2&amp;, typename boost::disable_if&lt;
      std::is_const&lt; T1 &gt;, T1 &gt;::type* = 0 ) {
  
          std::cout &lt;&lt; "non-const" &lt;&lt; std::endl;
      }
  };
  
  int main() {
      const int ci = 5;
      int i = 6;
  
      C&lt;char&gt; c;
      c.test(ci);
      c.test(i);
      return 0;
  }
  </code></pre>
  
  <p>But the following similar codes work fine:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;tr1/type_traits&gt;
  #include &lt;boost/utility.hpp&gt;
  
  namespace std {
      using namespace tr1;
  }
  
  template &lt;typename T1&gt;
  struct C {
      template&lt; typename T2 &gt;
      void test( T2&amp;, typename boost::enable_if&lt;
      std::is_const&lt; T2 &gt;, T1 &gt;::type* = 0 ) {
  
          std::cout &lt;&lt; "const" &lt;&lt; std::endl;
      }
  
      template&lt; typename T2 &gt;
      void test( T2&amp;, typename boost::disable_if&lt;
      std::is_const&lt; T2 &gt;, T1 &gt;::type* = 0 ) {
  
          std::cout &lt;&lt; "non-const" &lt;&lt; std::endl;
      }
  };
  
  int main() {
      const int ci = 5;
      int i = 6;
  
      C&lt;char&gt; c;
      c.test(ci);
      c.test(i);
      return 0;
  }
  </code></pre>
  
  <p>What I want to achieve is to disable/enable some member functions based the types declared in the class template. Actually the template member function is not needed. They're only added for SFINAE.</p>
  
  <p>Anyone can help??</p>
  
  <p>Thanks!</p>