Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.