Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread user1234 via Digitalmars-d-learn
On Thursday, 5 October 2023 at 22:24:06 UTC, mw wrote: On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote: If you have `T info`, T.tupleof[n] will always match up with info.tupleof[n]. You can think of `info.tupleof[n]` as being rewritten by the compiler in-place as

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread mw via Digitalmars-d-learn
On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote: If you have `T info`, T.tupleof[n] will always match up with info.tupleof[n]. You can think of `info.tupleof[n]` as being rewritten by the compiler in-place as info.whateverFieldThatIs. You might try this version (note the double {{ }}

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread cc via Digitalmars-d-learn
On Sunday, 1 May 2016 at 09:42:37 UTC, ParticlePeter wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin(

Re: Getting all struct members and values with introspection avoiding string mixins

2023-09-28 Thread mw via Digitalmars-d-learn
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)) {

Re: Getting all struct members and values with introspection avoiding string mixins

2016-05-01 Thread ParticlePeter via Digitalmars-d-learn
On Sunday, 1 May 2016 at 10:13:47 UTC, H. S. Teoh wrote: On Sun, May 01, 2016 at 09:42:37AM +, ParticlePeter via Digitalmars-d-learn wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) {

Re: Getting all struct members and values with introspection avoiding string mixins

2016-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 01, 2016 at 09:42:37AM +, ParticlePeter via Digitalmars-d-learn wrote: > I am logging arbitrary POD struct types with member names and data: > > void printStructInfo( T )( T info ) { > foreach( i, A; typeof( T.tupleof )) { > enum attribName = T.tupleof[i].stringof; >

Getting all struct members and values with introspection avoiding string mixins

2016-05-01 Thread ParticlePeter via Digitalmars-d-learn
I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin( "info." ~ attribName )); } } Is there is some other way