<br><br><div class="gmail_quote">On Fri, Jul 30, 2010 at 20:20, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com">andrej.mitrovich@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hey, just tried out your code.<br><br>In the first one there's a little typo (used 'i' instead of index), but that's ok. ;p<br></blockquote><div><br></div><div>Ah yes, that was typed over the course of 2-3 hours, with my children jumping around :)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>It seems like I don't need to use the to!() template. This code seems to work fine:<div class="im">
<br>
<br>void gun(T)(T value) {<br></div> foreach(Type; value.expand)<br> write(Type, " ");<br> <br> writeln();<br>}<br><br></blockquote><div><br></div><div>If you just want to print them, yes. In that case btw, do not use 'Type' as a name, as you're directly iterating on the values. Sorry, my mistake: I'm so used to iterate on typetuples, where the iteration is done on a index-Type pair that I typed that without thinking.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">But regardless, at least I now know how to traverse through my own tuples, so thanks for that one.<br>
</blockquote><div><br></div><div>As I said, value.expand is an instantiated typetuple, to it's iterable, indexed with [i], can be sliced with [i..j], it knows its length, etc. Very powerful stuff, very easy to use. None of the gobbledygook from C++.</div>
<div><br></div><div>Note that .field and .expand are aliases, they are the same access to the tuple's fields, under a different name.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>In your second example:<div class="im"><br><div><br></div><div>Tuple!("index", int, "sum", double) t =
tuple(1,3.14);</div><div><br></div><div>assert(t.index== 1); // t has
.first and .second as members.</div><div>assert(t.sum== 3.14);</div>
<br></div>I get an error way deep in the library itself (this could call for a better error message, methinks):<br>C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(320): Error: tuple index 2 exceeds 2<br><br>I've reversed the order, put types before identifiers and this works fine then:<br>
<br>Tuple!(int, "index", double, "sum") t = tuple(1, 3.14);<br></blockquote><div><br></div><div>Sorry also, I should have checked typecons docs.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>I'm not sure what you mean by "t has .first and .second as members", I can't seem to access those. Maybe you meant t.index and t.sum as members?<br></blockquote><div><br></div><div><br></div><div>Hem, as I said, I typed the mail over a few hours, the first version of the tuple was Tuple!((int, "first", double, "second"), but I found first and second a bit bland, so I changed that to .index and .sum.</div>
<div><br></div><div>Man, I made a mess of my explanation. I'm glad you still understood something :)</div><div><br></div><div><br></div><div><br></div></div>