static assert( !hasBasicMathOp!int ); // can't get int from expr(int * double) static assert( hasBasicMathOp!float ); static assert( hasBasicMathOp!double ); static assert( hasBasicMathOp!real ); static assert( hasBasicMathOp!cfloat ); static assert( !hasBasicMathOp!char ); static assert( !hasBasicMathOp!string ); static struct TTest { float x,y; auto opBinary(string op)( in TTest v ) const if( op=="+" || op=="-" ) { return TTest(x+v.x,y+v.y); } auto opBinary(string op)( double v ) const if( op=="*" || op=="/" ) { return TTest(x*v,y*v); } } static assert( hasBasicMathOp!TTest ); struct FTest { float x,y; auto opAdd( in TTest v ) const { return TTest(x+v.x,y+v.y); } } static assert( !hasBasicMathOp!FTest );
checks has type T basic math operations
* isAssignable!(Unqual!T,T) * is( typeof( T.init + T.init ) == T ) * is( typeof( T.init - T.init ) == T ) * is( typeof( ( T.init * 0.5 ) ) : T ) * is( typeof( ( T.init / 0.5 ) ) : T )