xxxxxxxxxx
import std.stdio;
struct Foo
{
private int _foo;
this(int i)
{
_foo = i;
}
foo() { return _foo; }
auto opBinary(string op)(const Foo rhs) const
{
static if (op == "+") return Foo(_foo + rhs._foo);
else static if (op == "-") return Foo(_foo - rhs._foo);
else static assert(0, "Operator "~op~" not implemented");
}
}
struct Bar
{
Foo f;
alias f this;
this(Foo f)
{
this.f = f;
}
}
void main(string[] args)
{
// How to help (or make) compiler to deduce that v5 is Bar type?
auto v5 = Bar(Foo(2)) + Bar(Foo(3));
pragma(msg, typeof(v5));
writefln("v5 = %s", v5);
}