www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Does anyone have a completed version of a d analogue to php's

reply Kevin Brogan <kevin brogan.ca> writes:
I can dump a struct easily enough with the following. I'm 
wondering if anyone else has done all the work to make it work 
for every type? https://code.dlang.org/ is down at the moment so 
I can't check there, and google hasn't been helpful.

========================================================================================

import std.traits;

void main()
{
	WSADATA wsa;
	dump!wsa;
}

void dump(alias variable)()
{
	writeln("\nDumping ",typeid(typeof(variable)),":\n");
	writeln(variable.stringof, " = \n{");
	foreach(member; FieldNameTuple!(typeof(variable)))
	{
		writeln("\t", member, ": ", mixin("variable."~member) );
	}
	writeln("}\n");
}

========================================================================================
Feb 24 2017
next sibling parent Seb <seb wilzba.ch> writes:
On Saturday, 25 February 2017 at 06:22:02 UTC, Kevin Brogan wrote:
 I can dump a struct easily enough with the following. I'm 
 wondering if anyone else has done all the work to make it work 
 for every type? https://code.dlang.org/ is down at the moment 
 so I can't check there, and google hasn't been helpful.

 ========================================================================================

 import std.traits;

 void main()
 {
 	WSADATA wsa;
 	dump!wsa;
 }

 void dump(alias variable)()
 {
 	writeln("\nDumping ",typeid(typeof(variable)),":\n");
 	writeln(variable.stringof, " = \n{");
 	foreach(member; FieldNameTuple!(typeof(variable)))
 	{
 		writeln("\t", member, ": ", mixin("variable."~member) );
 	}
 	writeln("}\n");
 }

 ========================================================================================
How about this? https://github.com/dlang/phobos/pull/4318
Feb 24 2017
prev sibling parent Martin Tschierschke <mt smartdolphin.de> writes:
On Saturday, 25 February 2017 at 06:22:02 UTC, Kevin Brogan wrote:
 I can dump a struct easily enough with the following.
[...]
 import std.traits;
[...]
 	dump!wsa;
[...]
 ========================================================================================
A good addition, thank you! To my question here: https://forum.dlang.org/post/foxuhcldegonvotchujv forum.dlang.org
Feb 27 2017