title: Restrict supported types of a template class by using variadic templates
body: <p>I'm trying to handle image processing operation classes which are only compatible for certain combinations of: </p>
  
  <ul>
  <li>a set of dimensions [1,2,3, ...]</li>
  <li>a set of types [int, float, double, ...]</li>
  </ul>
  
  <p>One working method would be to define a generic template class which handles the default-case (which is: do nothing) like this:</p>
  
  <pre><code>template &lt;int dimension, typename dataType&gt;
  class IPOperation
  {
  public:
      void execute()
      {
          std::cout &lt;&lt; "do nothing" &lt;&lt; std::endl;
      }
  };
  </code></pre>
  
  <p>Then I would have to write a specialization of that class for all supported type combinations, like for instance:</p>
  
  <pre><code>template&lt;&gt;
  class IPOperation&lt;2,float&gt;
  {
  public:
      void execute()
      {
          std::cout &lt;&lt; "do something" &lt;&lt; std::endl;
      }
  };
  </code></pre>
  
  <p>But since the number of supported dimension/type combinations can become really big, this approach is a total overkill..</p>
  
  <p>Inspired by policy driven design it would be nice to equip a template class with specific restrictions, something like this:</p>
  
  <pre><code>template &lt;int dimension, typename dataType&gt;
  class IPOperation : public supportedDimensions&lt;2,3,4&gt;, public supportedTypes&lt;int, float, double&gt;
  {
      void execute()
      {
          std::cout &lt;&lt; "execute()" &lt;&lt; std::endl;
      }
  };
  </code></pre>
  
  <p>My poor approach so far was this (and it seems pretty bad, I can't help myself):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  template &lt;int... supportedDimensions&gt;
  class IPDimensions
  {
  private:
  public:
      static std::vector&lt;int&gt; getSupportedDimensions()
      {
          return { supportedDimensions... };
      }
  
      static bool supportsDimension(int dim)
      {
          std::vector&lt;int&gt; dimensions = getSupportedDimensions();
          return std::find(dimensions.begin(), dimensions.end(), dim) != dimensions.end();
      }
  };
  
  template &lt;int dim&gt;
  class IPOperation : public IPDimensions&lt;2,3&gt;
  {
  private:
  public:
      void execute(void)
      {
          if(IPOperation::supportsDimension(dim))
          {
              std::cout &lt;&lt; dim &lt;&lt; "d is supported -&gt; execute" &lt;&lt; std::endl;
          }
          else
          {
              std::cout &lt;&lt; dim &lt;&lt; "d is not supported -&gt; sit down and do nothing" &lt;&lt; std::endl;
          }
      }
  };
  
  int main(int argc, const char * argv[])
  {
      IPOperation&lt;2&gt;* okay = new IPOperation&lt;2&gt;();
      IPOperation&lt;4&gt;* notOkay = new IPOperation&lt;4&gt;();
  
      okay-&gt;execute();
      notOkay-&gt;execute();
  }
  </code></pre>
  
  <p>When trying to apply something like this for types, I'm totally lost. It would be nice to have some sort of mechanism to do some checking like you use policies as delegates for specific strategies. Maybe my approach is the wrong way and this whole thing could be achieved much simpler via macros, enums or traits and std::enable_if to make functions only visible for defined scenarios, but since I spent some time reading through some c++11 topics, I'm really not sure about anything anymore.</p>
  
  <p>Thank you guys in advance for any helpful advice!</p>