How to "stringnify"?

evilrat evilrat666 at
Sun Oct 10 08:54:55 UTC 2021

On Sunday, 10 October 2021 at 08:28:30 UTC, rempas wrote:
> Is there a way to "stringnify" in Dlang? In C we would do 
> something like the following:
> `#define STRINGIFY(x) #x`
> What's the equivalent in D?

That's probably depends on what you are trying to achieve.

If you want to write code-like string that looks like a code you 
can use token strings

string code = q{
   float sqr(float x) { return x * x; }

For other symbols there is .stringof property (beware, it's 
behavior is not part of the spec)

class MyClass()
   static this() {
     registerSmth(MyClass.stringof); // pass "MyClass" string

And there is stuff for metaprogramming such like this in 

More information about the Digitalmars-d-learn mailing list