title: Specify template parameters at runtime
body: <p>Consider the following template class</p>
  
  <pre><code>class MyClassInterface {
  public:
    virtual double foo(double) = 0;
  }
  
  class MyClass&lt;int P1, int P2, int P3&gt;
  : public MyClassInterface {
  public:
    double foo(double a) {
      // complex computation dependent on P1, P2, P3
    }
    // more methods and fields (dependent on P1, P2, P3)
  }
  </code></pre>
  
  <p>The template parameters <code>P1</code>, <code>P2</code>, <code>P3</code> are in a restricted range like from <code>0</code> to some fixed value <code>n</code> fixed at compile time.</p>
  
  <p>Now I would like to build a "factory" method like</p>
  
  <pre><code>MyClassInterface* Factor(int p1, int p2, int p3) {
    return new MyClass&lt;p1,p2,p3&gt;(); // &lt;- how to do this?
  }
  </code></pre>
  
  <p>The question would be how to achieve the construction of the template class when template parameters are only known at runtime. And would the same be possible with template parameters having a very large domain (like a double)? Please consider also, if the possible solution is extendable to using more template parameters.</p>