digitalmars.D - Operator Overloading / Templates
- M Cardoso <M_member pathlink.com> Jul 02 2006
Is there any way to do templated operator overloading in D? That is something
like the following C++ code:
template< class T >
class Test {
...
template< class U >
Test operator+= ( Test<U> t ) {
...
}
..
};
int main() {
Test<double> u;
Test<float> v;
u += v;
}
In D I would try something like this:
class Test(T) {
...
Test opAddAssign(U)( Test!(U) t) {
...
}
.
}
or
class Test(T) {
...
template(U) opAddAssign {
Test opAddAssign( Test!(U) t ) {
...
}
}
}
But it seems to not work.
Jul 02 2006








M Cardoso <M_member pathlink.com>