How to design function interfaces that can deal with varied number of arguments or having any combination of argument types?
<p>Occasionaly I find that I need a generic "pass through"-interface. For example for mix-in classes that forward their constructor arguments to the parent. Or for factory methods that forward their arguments to <code>new</code>: </p>

<pre><code>template&lt;typename C&gt;
C * Create();

template&lt;typename C, typename Arg0&gt;
C * Create(Arg0 &amp; a);

template&lt;typename C, typename Arg0, typename Arg1&gt;
C * Create(Arg0 &amp; a, Arg1 &amp; arg1);

template&lt;typename C, typename Arg0, typename Arg1, typename Arg2&gt;
C * Create(Arg0 &amp; a, Arg1 &amp; arg1, Arg2 &amp; arg2);
</code></pre>

<p>When putting the idea into practice I find that it usually works.</p>

<p>However, there are a few problems:</p>

<ul>
<li><p>When passing the template arguments by value then sometimes reference-types drop their reference-ness along the way.</p></li>
<li><p>My attempted fix was so pass all arguments as non-const reference. This works for most of the cases because constness is preserved in the type itself and arguments that are passed by value are allowed to be converted to reference.</p></li>
<li><p>However, a notable exception is temporary const references. See my edit below for more info.</p></li>
</ul>

<p>All this however is only my personal experience. I haven't seen this approach much in other codebases. Because of this I am interested to learn your ideas and insights on above issues. </p>

<p>My main questions are:</p>

<ul>
<li><p>What are the general guidelines and best practices when designing this kind of interface?</p></li>
<li><p>How can I avoid losing type information? (Can it be avoided at all?)</p></li>
<li><p>Can you recommend any good examples of such a design?</p></li>
</ul>

<h3>Update</h3>

<p>In response to @Ben Voigt's comment. It seems he on to something. It works with a <code>const char *</code> string that is bound to an lvalue, but it doesn't work when passing the result of typeinfo's name() method:</p>

<pre><code>template&lt;typename Arg0&gt;
void Create(Arg0 &amp; a) {}

void foo()
{
    // works fine
    const char * typeName = typeid(int).name();
    Create(typeName);

    // error: invalid initialization of non-const reference of type
    // ‘const char*&amp;’ from a temporary of type ‘const char*’
    Create(typeid(int).name());
} 
</code></pre>
