A simple function to dump a struct's fields:
```dlang
void inspect_struct(T)(T t)
{
   (T).stringof.writeln;
   foreach(i, member; FieldNameTuple!T)
   {
     if (isPointer!(Fields!T[i]))
     {
       // error (sometimes)
writefln("%s %s = %s", Fields!T[i].stringof, member, (*t.tupleof[i]));
     }

     else
     {
writefln("%s %s = %s", Fields!T[i].stringof, member, (t.tupleof[i]));
     }

   }
}
```
I would also like to automatically deref any pointers for their values.
This works if all fields in a struct are pointers.
But for any fields that aren't, you get an error:
```
Error: can only `*` a pointer, not a `ushort`
```
What am I missing / What would be the proper way to do this?
  • Printing struct ... z via Digitalmars-d-learn
    • Re: Printin... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Reply via email to