<div dir="ltr">and this:<div><div>auto tupleFields(T)()if(isTuple!T){</div><div>  string[T.length]ret;</div><div>  foreach(i;Iota!(T.length))</div><div>    ret[i]=tupleField!(T,i);</div><div>  return ret;</div><div>}</div>
<div>unittest{</div><div>  import std.typecons;</div><div>  auto t=Tuple!(int,"foo",double,"bar")(2,3.4);</div><div>  alias T=typeof(t);</div><div>  static assert(tupleFields!T==["foo","bar"]);</div>
<div>}</div></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Aug 18, 2013 at 2:26 AM, Timothee Cour <span dir="ltr"><<a href="mailto:thelastmammoth@gmail.com" target="_blank">thelastmammoth@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 dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On Sun, Aug 18, 2013 at 2:15 AM, John Colvin <span dir="ltr"><<a href="mailto:john.loughran.colvin@gmail.com" target="_blank">john.loughran.colvin@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On Sunday, 18 August 2013 at 08:46:17 UTC, Timothee Cour wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
A)<br>
how do I get the ith field of a std.typecons.Tuple ?<br>
ideally, it should be as simple as:<br>
<br>
auto t=Tuple!(int,"name",double,"<u></u>name2")(1);<br>
static assert(t.fields[0] == "name");<br>
</blockquote>
<br></div>
field is the old name for expand, retained for compatibility, it's not recommended. It gives you direct access to the tuple inside the Tuple struct, but it's for getting the variable values, not their names.<br></blockquote>

<div><br></div></div><div>I didn't mean Tuple.field (as in Tuple.expand), I really meant the name of the corresponding entry, as shown in my example. </div><div class="im"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


If you want to get the *names* you've chosen for the tuple fields, you'll have to use traits of some sort I think.<br></blockquote><div><br></div></div><div>I don't see how that would work, however I've figured out how to do it:</div>

<div><br></div><div>That's a bit of a hack, but should work. Should it be included in phobos, or, better, shall we fix Tuple with some of the recommendations i gave above?</div><div>----</div><div>import std.typecons;</div>

<div>auto tupleField(T,size_t i)()if(isTuple!T && i<T.length){</div><div>  enum foo0=typeof(T.init.slice!(i,i+1)).stringof;</div><div>  static assert(foo0[$-2..$]==`")`);//otherwise not a tuple with fields</div>

<div>  enum foo=typeof(T.init.slice!(i,i+1)).stringof[0..$-2];</div><div>  size_t j=foo.length;</div><div>  while(true){</div><div>    char fj=foo[--j];</div><div>    if(fj=='"')</div><div>      return foo[j+1..$];</div>

<div>  }</div><div>}</div><div>unittest{</div><div>  import std.typecons;</div><div>  auto t=Tuple!(int,"foo",double,"bar")(2,3.4);</div><div>  alias T=typeof(t);</div><div>  static assert(tupleField!(T,0)=="foo");</div>

<div>  static assert(tupleField!(T,1)=="bar");</div><div>}</div><div>----</div><div> </div></div><br></div></div>
</blockquote></div><br></div>