Search code examples
stringreflectiontype-conversiondcompile-time

Type as a String


How do I convert a type to a string?

I thought something like this should work

import std.stdio: writeln;
import std.conv: to;
writeln(to!string(int));

Update: I found it at http://dlang.org/phobos/std_traits.html#.fullyQualifiedName

I guess all logic in D operating on types are given as templates arguments right?


Solution

    1. int is already a type. You don't need to typeof it.

    2. You could use the .stringof property to get a string representation. http://ideone.com/T4yYmo

      writeln(int.stringof);