How to convert int type to string "int" ?

bioinfornatics via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 1 07:11:11 PDT 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:
>> Maybe http://dlang.org/property.html#stringof helps.
>
> yes that help a lot thanks

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;
}


More information about the Digitalmars-d-learn mailing list