July 02, 2006 Operator Overloading / Templates | ||||
---|---|---|---|---|
| ||||
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. |
Copyright © 1999-2021 by the D Language Foundation