Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created May 5, 2025 20:31
Show Gist options
  • Save crazymonkyyy/248194bd1ecfc96a1477dcc9ab55c90b to your computer and use it in GitHub Desktop.
Save crazymonkyyy/248194bd1ecfc96a1477dcc9ab55c90b to your computer and use it in GitHub Desktop.
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