digitalmars.D.learn - How to convert int type to string "int" ?
- bioinfornatics (32/32) Jun 01 2014 Hi,
- bioinfornatics (5/40) Jun 01 2014 I find this: typeid(typeof(__traits(getMember, T,
- Tobias Pankrath (1/1) Jun 01 2014 Maybe http://dlang.org/property.html#stringof helps.
- bioinfornatics (2/3) Jun 01 2014 yes that help a lot thanks
- bioinfornatics (34/37) Jun 01 2014 End of spam ( joke ^^)
- bioinfornatics (33/33) Jun 01 2014 I bam close to be done
Hi, All is in the title. I need this to do a tupleof enhanced, that mean: - .tupleof need an instance me i want to do this on type diretcly - .tupleof do not bind to member name i need this for this i strat to this code: import std.stdio; import std.typecons; import std.conv; struct Coord { int x; int y; int z; } template toTuple(T){ static string maker(){ string statement = "alias Tuple!("; foreach(const memberName; __traits(allMembers, T)){ statement ~= to!string(typeof(__traits(getMember, T, memberName))) ~ ",\"" ~ memberName ~ "\", " ; } statement = statement[O..$-1] ~ ") t;" ; // $-1 to remove extra comma return statement; } enum toTuple = mixin( maker() ); } but that fail on typeof(__traits(getMember, T, memberName) becase that return a type and not a string. Thaks for your help
Jun 01 2014
On Sunday, 1 June 2014 at 13:34:20 UTC, bioinfornatics wrote:Hi, All is in the title. I need this to do a tupleof enhanced, that mean: - .tupleof need an instance me i want to do this on type diretcly - .tupleof do not bind to member name i need this for this i strat to this code: import std.stdio; import std.typecons; import std.conv; struct Coord { int x; int y; int z; } template toTuple(T){ static string maker(){ string statement = "alias Tuple!("; foreach(const memberName; __traits(allMembers, T)){ statement ~= to!string(typeof(__traits(getMember, T, memberName))) ~ ",\"" ~ memberName ~ "\", " ; } statement = statement[O..$-1] ~ ") t;" ; // $-1 to remove extra comma return statement; } enum toTuple = mixin( maker() ); } but that fail on typeof(__traits(getMember, T, memberName) becase that return a type and not a string. Thaks for your helpI find this: typeid(typeof(__traits(getMember, T, memberName))).toString but that do not works at compile time. Error: static variable typeid(int) cannot be read at compile time
Jun 01 2014
Maybe http://dlang.org/property.html#stringof helps.
Jun 01 2014
On Sunday, 1 June 2014 at 13:52:27 UTC, Tobias Pankrath wrote:Maybe http://dlang.org/property.html#stringof helps.yes that help a lot thanks
Jun 01 2014
On Sunday, 1 June 2014 at 13:58:03 UTC, bioinfornatics wrote:On Sunday, 1 June 2014 at 13:52:27 UTC, Tobias Pankrath wrote:End of spam ( joke ^^) I found it :-) import std.stdio; import std.typecons; import std.conv; struct Coord { int x; int y; int z; } template toTuple(T){ static string maker(){ string statement = "alias toTuple = Tuple!("; foreach(const memberName; __traits(allMembers, T)){ statement ~= typeof(__traits(getMember, T, memberName)).stringof ~ ",\"" ~ memberName ~ "\", " ; } statement = statement[0..$-2] ~ ") ;" ; // $-1 to remove extra comma return statement; } pragma( msg, maker() ); mixin( maker() ); } void main() { Coord c; alias A = toTuple!Coord; A a; a[0] = 1; a.x = 1; }Maybe http://dlang.org/property.html#stringof helps.yes that help a lot thanks
Jun 01 2014
I bam close to be done import std.stdio; import std.typecons; import std.conv; struct Coord { int x; int y; int z; } template toTuple(T){ static string maker(){ string statement = "alias Tuple!("; foreach(const memberName; __traits(allMembers, T)){ statement ~= typeof(__traits(getMember, T, memberName)).stringof ~ ",\"" ~ memberName ~ "\", " ; } statement = statement[0..$-2] ~ ") toTuple;" ; // $-1 to remove extra comma return statement; } pragma( msg, maker() ); mixin( maker() ); } void main() { //auto a = c.tupleof; auto a = toTuple!Coord; } $ ldc2 -w -of"testTupleof" "testTupleof.d" alias Tuple!(int,"x", int,"y", int,"z") toTuple; testTupleof.d(29): Error: type Tuple!(int, "x", int, "y", int, "z") has no value
Jun 01 2014