title: c++ enable_if for non-type template parameters
body: <p>I'm a bit confused about partial template specialization... I have some code that depends on an arithmetic data type T, and on a small integer DIM. I want to be able to specify different class methods for different values of DIM. The impossibility of using partial template specialization led me to explore enable_if. It's exactly what I needed... except I want it to return a number and not a type. How can I do that? The following code should illustrate what I want.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  
  template &lt;typename T, int DIM&gt;
  class foo{
      public:
          T function();
  
  };
  
  
  template &lt;typename T, int DIM&gt;
  T foo&lt;T, std::enable_if&lt;DIM == 1&gt;::value&gt;::function(){
      // do something
      return 1.0;
  }
  
  template &lt;typename T, int DIM&gt;
  T foo&lt;T, std::enable_if&lt;DIM == 2&gt;::value&gt;::function(){  
      // do something else
      return 2342.0;
  }
  
  int main(){
      foo&lt;int, 1&gt; object;
      int ak = object.function();
      std::cout &lt;&lt; ak &lt;&lt; "\n";
  
      return 0;   
  }
  </code></pre>