title: C++ runtime decision for a template type
body: <pre><code> template&lt;typename T&gt;
   class A
   { std::vector&lt;T&gt; v;
     .... //other variables
     void op1();
     void op2();
     ... //other operations
   };
  
   int main()
   {
     string type;
     cout&lt;&lt;"which type do you need?"
     cin&gt;&gt;type;
     if(type=="int")
        A&lt;int&gt; ai;
     else  A&lt;float&gt; af;
  
     return 0;
   }
  </code></pre>
  
  <p>In both blocks I must do the same flow of instructions.
  for example:</p>
  
  <pre><code> ai.op1();
   ai.op2();
   ...
  </code></pre>
  
  <p>If they are only two I can write it two times but it is a horrible solution with a lot of conditions. Is there a way to do this once for a chosen type after "if-else"? I can't say which type wil be chosen? How should I do?</p>