C++ conditional construction of template type
<p>I would like to be able to do something like the following:</p>

<pre><code>struct A {};

template&lt;typename T, typename U&gt; struct B : public A {};

std::unique_ptr&lt;A&gt; chooseB(int i, int j)
{
  // return B&lt;T, U&gt; where T and U vary with i and j (0 = int, 1 = double etc.) 
}
</code></pre>

<p><code>i</code> and <code>j</code> are not known at compile time. Potentially the list of types could be long enough that just forming a big conditional that enumerates all possible pairs of <code>i</code> and <code>j</code> could be painful.</p>

<p>Is there are nice way to write the <code>chooseB</code> function? I might potentially want to generalize this to more than two template parameters.</p>