digitalmars.D - type promotion (on overloaded operators)
- wondermail szm.sk (25/25) Oct 10 2004 Hi there,
Hi there, I've just read the spec - great D, but can I somehow do the "type promotion" e.g. for matrices class CMatrix(T, int M, int N) { T data[M][N]; } CMatrix!(float,3,3) mf; CMatrix!(double,3,3) md; mf + md; // float matrix + double matrix = double matrix // or CMatrix!(float,1,3) v3; CMatrix!(float,3,3) m33; v3 * m33; // and this is really necessary to me ----------- In C++ I did something like this: template <class X, class Y> TAdd {}; template <> TAdd<float,double> { typedef double RET; }; // float + double = double template <class X, class Y, int M, int N> CMatrix<typename TAdd<X,Y>::RET,M,N> operator + (CMatrix<T,M,N> const &a, CMatrix<T,M,N> const &b) { /*...*/ } thanks Juraj Onderik (as I understand templates in D now - it's not really superset of C++ templates, or is it? :) Juraj Onderik
Oct 10 2004