Getting all struct members and values with introspection avoiding string mixins
mw
m at g.c
Fri Sep 29 02:48:23 UTC 2023
On Sunday, 1 May 2016 at 10:13:47 UTC, H. S. Teoh wrote:
>
> Using typeof(T.tupleof) seems a bit circuitous. Here's how I'd
> do it:
>
> void printStructInfo( T )( T info ) {
> import std.stdio : writefln;
> foreach (memb; __traits(allMembers, T)) {
> writefln("%s: %s", memb,
> __traits(getMember, info, memb));
> }
> }
>
> (For structs that have members other than data fields, you'll
> need a static if to filter out non-value members, but this
> should get you started.)
How to check `isAlias`? e.g.
```
struct foo {
int bar;
alias bar baz;
}
```
I want to filter out baz (right now, it's included).
More information about the Digitalmars-d-learn
mailing list