d的中缀操作
struct Operator(alias fn, string operator = "/")
{
static auto opBinaryRight(string op : operator, T...)(T value1)
{
struct Result
{
auto opBinary(string op : operator, U...)(U value2)
if (__traits(compiles, fn(value1, value2)))
{
return fn(value1, value2);
}
}
Result result;
return result;
}
}
void main()
{
import std.algorithm.comparison;
alias min = Operator!(std.algorithm.comparison.min, "%");
assert(1 %min% 3 == 1);
}