Created
May 5, 2025 20:31
-
-
Save crazymonkyyy/248194bd1ecfc96a1477dcc9ab55c90b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std; | |
void printctfe(alias A)(string s=""){ | |
if(__ctfe){ | |
__ctfeWrite("ct:"~A.to!string~":"~s~"\n"); | |
} else { | |
writeln("rt:",A,":",s); | |
}} | |
template counter(discrim...){ | |
enum counter=cast(immutable(void)*)[0].ptr; | |
} | |
int count(discrim...)()=>(*(cast(int*)counter!discrim))++; | |
template stringof2(alias A,int line=__LINE__){ | |
enum s=A.stringof; | |
enum i=count!A; | |
enum stringof2=s~i.to!string; | |
} | |
unittest{ | |
stringof2!int.writeln; | |
stringof2!float.writeln; | |
stringof2!int.writeln; | |
stringof2!bool.writeln; | |
stringof2!bool.writeln; | |
stringof2!bool.writeln; | |
stringof2!"foo".writeln; | |
} | |
unittest{ | |
stringof2!"foo".writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment