How to "stringnify"?

rempas rempas at tutanota.com
Sun Oct 10 09:52:33 UTC 2021


On Sunday, 10 October 2021 at 08:54:55 UTC, evilrat wrote:
>
> 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
>
> https://dlang.org/spec/lex.html#token_strings
>
> ```d
> 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)
>
> https://dlang.org/spec/property.html#stringof
>
> ```d
> class MyClass()
> {
>   static this() {
>     registerSmth(MyClass.stringof); // pass "MyClass" string
>   }
> }
> ```
>
> And there is stuff for metaprogramming such like this in 
> std.traits
>
> https://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple

".stringof" will probably do the job! If not I will check 
"token_strings". Thanks a lot!



More information about the Digitalmars-d-learn mailing list