xxxxxxxxxx
import std.algorithm : among;
import std.traits : isIntegral, isFloatingPoint;
mixin template Scale(alias u)
{
auto ref opBinary(string op, this T, B)(auto ref B rhs)
if (op.among("*", "-") && (isIntegral!B || isFloatingPoint!B))
{
T result = T(mixin("u" ~ op ~ "rhs"));
return result;
}
}
mixin template AddSub()
{
auto ref opBinary(string op, this T)(auto ref T rhs)
if (op.among("+", "-"))
{
T result = T(mixin("underlying" ~ op ~ "rhs.underlying"));
return result;
}
}
struct WrapInt
{
int underlying;
//mixin Scale!underlying;
mixin AddSub!();
}
unittest {
WrapInt a = WrapInt(5);
WrapInt b = WrapInt(10);
assert (a + b == WrapInt(15));
//assert (a * 3 == WrapInt(15));
}
void main()
{
}