Inline Operator from Function.

Jonathan Levi catanscout at gmail.com
Fri Jan 25 03:45:36 UTC 2019


I know this was not an intentional feature of d, but it is a cool 
quirk.

If you want to use a function that takes two arguments like a 
infix binary operator (similar to the back ticks in Haskell 
"`fun`") you can but a "." before and a "=" after.

     c = (a .fun= b);

Example of it working (https://run.dlang.io/is/rr7ChO)

     import std.stdio;

     void main() {
         writeln(5 .mul= 2);
     }

     int mul(int a, int b) {
     	return a*b;
     }




More information about the Digitalmars-d mailing list