Skip to content

Instantly share code, notes, and snippets.

@nin-jin
Last active October 9, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nin-jin/e52e51a68e5a6b17c6fb to your computer and use it in GitHub Desktop.
Save nin-jin/e52e51a68e5a6b17c6fb to your computer and use it in GitHub Desktop.
import std.stdio;
T eval( string op , T )( T a , T b ) {
return mixin( q{a} ~ op ~ q{b} );
}
unittest {
writeln( eval!q{/}( 123 , 0 ) );
}
//object.Error@(0): Integer Divide by Zero
//----------------
//0x0040BA03 in pure nothrow @nogc @safe int xxx.eval!("/", int).eval(int, int) at /xxx/xxx.d(4)
//0x004031CC in void xxx.__unittestL7_8() at /xxx/xxx.d(8)
import std.stdio;
mixin template makeX() {
auto x = ( int a ){
return 1 / a;
};
}
unittest {
mixin makeX;
writeln( x(0) );
}
// object.Error@(0): Integer Divide by Zero
// ----------------
// 0x004031E5 in pure nothrow @nogc @safe int xxx.__unittestL9_8().__mixin1.__lambda2(int) at /xxx/xxx.d(5)
// 0x004031D1 in void xxx.__unittestL9_8() at /xxx/xxx.d(11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment