You could probably make a template out of the ugly __traits invocation as well? <br><br><div class="gmail_quote">On Sat, Apr 9, 2011 at 3:37 PM, 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;"><div><div></div><div class="h5">On 4/10/11, Jonathan M Davis <<a href="mailto:jmdavisProg@gmx.com">jmdavisProg@gmx.com</a>> wrote:<br>

>> What the.. I was sure mixin wouldn't work in a foreach loop.<br>
><br>
> Whyever not? mixins work in most places. I believe that the problem is that<br>
> they have to be a whole expression or statement rather than just a piece of<br>
> one, so sometimes you can't use a mixin for something small and have to put<br>
> more of the code in a mixin, but string mixins do work in most places.<br>
><br>
> - Jonathan M Davis<br>
><br>
<br>
</div></div>Well in this case it works, but it's not always so easy. For example:<br>
<br>
import std.conv;<br>
enum Metrics : int<br>
{<br>
    val0,<br>
    val1,<br>
    val2<br>
<div class="im">}<br>
<br>
void foo(int m)<br>
{<br>
}<br>
<br>
void main()<br>
{<br>
</div>   foreach (index; 0..3)<br>
   {<br>
       foo(mixin("Metrics.val" ~ to!string(index)));<br>
   }<br>
}<br>
<br>
So even though you might think "hey, it's obvious index in this case<br>
can never be anything other than 0, 1, or 2", you still won't be able<br>
to compile this. CTFE is a tricky thing.<br>
</blockquote></div><br>