Created
April 24, 2024 03:59
-
-
Save crazymonkyyy/4894100c6339f893677b3571ca8286e1 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; | |
string expandmixin(string s){ | |
return "static if( __traits(compiles,"~s~")){ return "~s~";}"; | |
} | |
unittest{ | |
expandmixin("foo").writeln; | |
} | |
string elsejoin(string[] s){ | |
auto l=s.length; | |
return s.map!(a=>[a]).joiner([" else "]).take(l*2-1).joiner.to!string; | |
} | |
unittest{ | |
elsejoin(["foo","bar"]).writeln; | |
} | |
template trycompilies(string[] mixins){ | |
//auto trycompilies()=>mixins.map!expandmixin.array.elsejoin; | |
mixin("auto trycompilies(){"~mixins.map!expandmixin.array.elsejoin~"}"); | |
} | |
unittest{ | |
trycompilies!(["(){static assert(0);}","2","3"])().writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment