bearophile <[email protected]> wrote:

So I think it's not worth adding to D.

But if you don't agree... talk.

This is basically already possible in D:

struct InfixOperator( alias fn ) {
    auto opBinaryRight( string op : "/", T )( T lhs ) {
        struct crazy {
            T value;
            auto opBinary( string op : "/", U )( U rhs ) {
                return fn( rhs, value );
            }
        }
        return crazy(lhs);
    }
}

@property auto _( alias fn )( ) {
    return InfixOperator!fn( );
}

T add( T )( T a, T b ) {
        return a + b;
}
unittest {
    assert( 2 /_!add/ 3 == 5 );
}



--
Simen

Reply via email to