How to get struct's members ?

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 23 01:19:51 PDT 2014


On Fri, May 23, 2014 at 8:44 AM, monarch_dodra via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
> On Friday, 23 May 2014 at 01:17:18 UTC, bioinfornatics wrote:


>> I would like to get struct's members and zip them with an action

> 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.

You can define a map-like (or zip-like) template to act on tuples as
if they were ranges, but the resulting type will still be a tuple: in
general, the members and the delegates associated with them will all
have a different type.

Bioinfornatics, if you know your struct members are all of the same
type, you can 'cast' the tuple as an array by wrapping it in square
brackets like this:

[ myStruct.tupleof ]

and then use the usual range algorithms.

If that's not the case, you can create another struct, holding both
the original struct and the delegates...

I did some generic range-like work on tuples a few years ago. See for example:

https://github.com/PhilippeSigaud/dranges/blob/master/tuple.d#L620

Could you explain what you want with more details?


More information about the Digitalmars-d-learn mailing list