Thread overview | |||||
---|---|---|---|---|---|
|
June 30, 2016 Tuple fields/types | ||||
---|---|---|---|---|
| ||||
Hello, For tuples, does the fieldNames property have a 1-1 correspondence with the Types property? It appears that way in my testing: alias MyData = Tuple!(string,"a",int,"b"); foreach (i, type; MyData.Types){ writeln (MyData.fieldNames[i]," ",type.stringof); // a string // b int } But I can't figure out for sure from the documentation: alias fieldNames = staticMap!(extractName, fieldSpecs); alias Types = staticMap!(extractType, fieldSpecs); Thanks, Jordan |
July 01, 2016 Re: Tuple fields/types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jordan Wilson | On Thursday, 30 June 2016 at 21:53:42 UTC, Jordan Wilson wrote:
> Hello,
>
> For tuples, does the fieldNames property have a 1-1 correspondence with the Types property?
>
> It appears that way in my testing:
>
> alias MyData = Tuple!(string,"a",int,"b");
> foreach (i, type; MyData.Types){
> writeln (MyData.fieldNames[i]," ",type.stringof);
> // a string
> // b int
> }
>
> But I can't figure out for sure from the documentation:
>
> alias fieldNames = staticMap!(extractName, fieldSpecs);
> alias Types = staticMap!(extractType, fieldSpecs);
>
> Thanks,
>
> Jordan
static map (and map in general) is a 1:1 correspondence, so yes.
|
July 01, 2016 Re: Tuple fields/types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jordan Wilson | On Thursday, 30 June 2016 at 21:53:42 UTC, Jordan Wilson wrote:
> Hello,
>
> For tuples, does the fieldNames property have a 1-1 correspondence with the Types property?
>
> It appears that way in my testing:
>
> alias MyData = Tuple!(string,"a",int,"b");
> foreach (i, type; MyData.Types){
> writeln (MyData.fieldNames[i]," ",type.stringof);
> // a string
> // b int
> }
>
> But I can't figure out for sure from the documentation:
>
> alias fieldNames = staticMap!(extractName, fieldSpecs);
> alias Types = staticMap!(extractType, fieldSpecs);
>
> Thanks,
>
> Jordan
It's an implementation detail but I wouldn't expect the order to ever change.
|
Copyright © 1999-2021 by the D Language Foundation