title: How to replace a template parameter in a given type?
body: <p>Given that a template parameter called <code>B</code> is of type <code>C&lt;D&gt;</code> (on instantiation), how can I construct <code>C&lt;A&gt;</code> from <code>B</code>?</p>
  
  <p>Here is a minimalized extract from my code:</p>
  
  <pre><code>template&lt;typename A&gt;
  class foo {
      template&lt;typename B&gt; // B is guaranteed to always be of the form C&lt;D&gt;
      // How to write a function here with return type C&lt;A&gt;?
  }
  </code></pre>