How to get struct's members ?

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 22 23:44:33 PDT 2014


On Friday, 23 May 2014 at 01:17:18 UTC, bioinfornatics wrote:
> Dear,
>
> I would like to get struct's members and zip them with an action
>
> as
>
> struct A
> {
>   int a;
>   int b;
> }
>
> std.range.zip( __traits( allmembers, A ), [(x) => x == 0, (y) =>
> y > 3] );
>
> like this i could apply an action to each field.
>
> I tried this:
> http://dpaste.dzfl.pl/747799ffa64e
>
> but:
>   tuple get by allmembers is not an input rage then i can't to 
> use
> zip
>   allmembers return both fiels and method while i would like 
> only
> fields
>
> thanks

tupleof will do what you need (mostly). However, I don't think 
there will be any way to (generically) run-time zip on the 
members, due to probably type mismatch, and memory layout. In any 
case, nothing trivial, AFAIK.


More information about the Digitalmars-d-learn mailing list