<br><div class="gmail_quote">On Sun, Mar 7, 2010 at 19:53, Ellery Newcomer <span dir="ltr">&lt;<a href="mailto:ellery-newcomer@utulsa.edu">ellery-newcomer@utulsa.edu</a>&gt;</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;">
<div><div></div><div class="h5">On 03/07/2010 12:23 PM, Jacob Carlborg wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
It&#39;s a bug: <a href="http://d.puremagic.com/issues/show_bug.cgi?id=2411" target="_blank">http://d.puremagic.com/issues/show_bug.cgi?id=2411</a><br>
You can use the following code as a workaround:<br>
<br>
foreach (i, dummy ; s.tupleof)<br>
s.tupleof[i] = 1;<br>
</blockquote>
<br></div></div>
Totally awesome! Thanks a float.infinity!<br></blockquote><div><br>I remember spending *weeks* (well, OK, *hours*) trying to find a way to do such a mapping after trying the first foreach, and getting some recursive template to work... Only to find this static foreach trick, looking at Phobos code (for D2) some month after. It sent ripples in all my code...<br>
<br>As a side note, it works for any tuple: those created by .tupleof, but also the variadic template parameters, the expansion of a std.typecons.Tuple (D2), those created by templates, etc. So you can do:<br><br>void reinitialize(T...)(ref T ts) // Variadic template<br>
{<br>    foreach(i, Type; T) ts[i] = T[i].init; // iterating on the components of T.<br>}<br><br>int a = 1; <br>char c = &#39;a&#39;; <br>string s = &quot;abc&quot;;<br><br>reinitialize(a,c,s);<br><br>assert(a = 0); // int.init<br>
assert(c =  char.init); // is there a literal for char.init? &#39;&#39; doesn&#39;t work.<br>assert(s=&quot;&quot;);<br> <br><br></div></div>Philippe<br><br>