<div class="gmail_quote">On Thu, Mar 11, 2010 at 21:03, BCS <span dir="ltr"><<a href="mailto:none@anon.com">none@anon.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><div class="im"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
i.e.<br>
<br>
static C create(Args...)(int foo, float bar, Args args)<br>
{<br>
auto c = new C(foo, bar);<br>
c.t = T(args);<br>
return c;<br>
}<br>
</blockquote>
<br></div>What about a static function instead of a constructor?<br></blockquote><div><br>Two variations on the same theme:<br><br>storing (Args...) as a template parameter in the host class<br><br>class Host(Hosted, Args...) {<br>
Hosted t;<br> this(int foo, float bar, Args args)<br> {<br> t = Hosted(args);<br> }<br>}<br><br>and using a helper function to do the type extraction:<br><br>Host!(Hosted, Args) host(Hosted, Args...)(int foo, float bar, Args args)<br>
{<br> return new Host!(Hosted, Args)(foo, bar, args);<br>}<br><br>Or, give the host a constructor taking a Hosted already created:<br><br><br>class Host2(Hosted) {<br> Hosted h;<br> this(int foo, float bar, Hosted h)<br>
{<br> this.h = h;<br> }<br>}<br><br>Host2!(Hosted) host2(Hosted, Args...)(int foo, float bar, Args args)<br>{<br> auto h = Hosted(args);<br> return new Host2!(Hosted)(foo, bar, h);<br>}<br><br>Usage:<br>
<br>struct OneArg { char c;}<br><br>struct ManyArgs { int i; float f;}<br><br>void main()<br>{<br> auto c0 = host!ManyArgs(1,2.0,3,4.0);<br> auto c1 = host!OneArg(1,2.0,'c');<br> auto c2 = host2!ManyArgs(1,2.0,3,4.0);<br>
}</div></div>