<div class="gmail_quote">On Sun, Sep 19, 2010 at 03:43, Juanjo Alvarez <span dir="ltr"><<a href="mailto:juanjux@gmail.com">juanjux@gmail.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;">
> enum string code = "auto deleg = &" ~ className ~ "." ~ methodName ~ ";";<br><div class="im">
> // auto deleg = &MyClass.mymethod;<br>
> mixin(code); // created deleg, you're good to go.<br>
<br>
</div>I tried it and worked like a charm (but I've changed my code so instead of<br>
two strings to class + method, a fully qualified non member function address<br>
is used so I have a little more flexibility).<br></blockquote><div><br>String mixins are quite powerful, if a bit clunky at times.<br><br>See also __traits(getMember, ...)<br><a href="http://digitalmars.com/d/2.0/traits.html">http://digitalmars.com/d/2.0/traits.html</a> (look for getMember)<br>
<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im"><br>
</div><div class="im">> Use the .field or .expand alias, exposed by Tuple!() to get a direct<br>
> access to the internal expression tuple.<br>
><br>
> f(tup.expand); // cracks tup open<br>
<br>
</div>Now, that is exactly what I wanted. It even works if the function has<br>
aditional arguments before the expanded tuple one's:<br>
<br>
//<br>
void f(int a, int b, double c) {<br>
writeln(a); writeln(b); writeln(c);<br>
<div class="im">}<br></div></blockquote><div> </div><div><br>Yes, because tuple.expand is directly the expression tuple stored inside Tuple!(...)<br>When you have a typetuple in a template, like this:<br><br>template List(T...)<br>
{<br>}<br><br>The T... part is a typetuple: an array of types, if you wish. You can get its length, index it, slice it, iterate on it, etc.<br>You can have a variable with this strange 'type' and also get its length, etc.<br>
<br>template List(T...)<br>{<br> T t;<br>}<br><br>t is an expression tuple. std.typecons.Tuple is nothing more than the preceding List!(...), with a few more functionalities.<br>So, something interesting is that when you do tup.expand, you obtain a bunch of values of different types, all perfectly individually typed and usable. You can get one by indexing, slice it, etc.<br>
<br>So, given your new f, you can even do:<br><br><div class="im">
auto tup = tuple(42, 3.14);<br>
</div>f(tup.expand[0], 1, tup.expand[1]);<br><br>Though in this particular case, it's cleaner to do:<br><br>f(tup[0], 1, tup[1]); <br><br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Wonderful. I wish it was better documented on<br>
<a href="http://digitalmars.com/d/2.0/phobos/std_typecons.html" target="_blank">http://digitalmars.com/d/2.0/phobos/std_typecons.html</a><br>
<div class="im"><br></div></blockquote><div><br>Yes, typecons.Tuple has lot of nifty things going for it, but there are not all documented.<br>You can open a bug/enhancement request at <a href="http://d.puremagic.com/issues/">http://d.puremagic.com/issues/</a><br>
<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im"><br>
</div>Nice to know. I got you excellent explanation.<br>
<br>
Thanks * 100,<br>
<br></blockquote><div><br>My pleasure,<br><br>Philippe <br></div></div>