title: Variadic template templates and perfect forwarding
body: <p><a href="https://stackoverflow.com/questions/6485791/c-instantiate-a-templated-class-according-to-an-argument/6485843#6485843">This question</a> on the <a href="http://en.wikibooks.org/wiki/More_C++_Idioms/Object_Generator" rel="noreferrer">object generator pattern</a> got me thinking about ways to automate it.</p>
  
  <p>Essentially, I want to automate the creation of functions like <code>std::make_pair</code>, <code>std::bind1st</code> and <code>std::mem_fun</code> so that instead of having to write a different function for each template class type, you could write a single variadic template template function that handles all cases at once. Usage of this function would be like:</p>
  
  <pre><code>make&lt;std::pair&gt;(1, 2);         // equivalent to std::make_pair(1, 2)
  make&lt;std::binder2nd&gt;(&amp;foo, 3); // equivalent to std::bind2nd(&amp;foo, 3);
  </code></pre>
  
  <p>Is it possible to write this function <code>make</code>? I have tried this, but it doesn't work in GCC 4.5 or 4.6:</p>
  
  <pre><code>template &lt;template &lt;typename...&gt; class TemplateClass, typename... Args&gt;
  TemplateClass&lt;Args...&gt; make(Args&amp;&amp;... args)
  {
      return TemplateClass&lt;Args...&gt;(std::forward&lt;Args&gt;(args)...);
  }
  </code></pre>
  
  <p>If I try to call (e.g) <code>make&lt;std::pair&gt;(1, 2)</code> I just get</p>
  
  <pre><code>error: no matching function for call to 'make(int, int)'
  </code></pre>
  
  <p>Have I got the syntax wrong anywhere here?<br>
  Or is this right and GCC is wrong?<br>
  Or is this just fundamentally impossible in C++0x?</p>
  
  <p>[edit]</p>
  
  <p>Proposal <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2555.pdf" rel="noreferrer">N2555</a> seems to suggest that this is allowed and <a href="http://gcc.gnu.org/projects/cxx0x.html" rel="noreferrer">GCC claims to have implemented it in GCC4.4</a>.</p>