Let's suppose I've got a 2D vector template class:
template<typename T> class Vec2 {
T x, y;
// ...
};
I'd expect that the result of a sum between a Vec2<double>
and a Vec2<int>
would be a Vec2<double>
, but C++ won't do this by default.
Am I thinking in the wrong way?
Should I try and implement this behavior?
And how would I be supposed to implement that? One way could be overloading any operator so that the promoted type is computed using auto
and decltype
or some do it yourself type promotion, but this way is anything but trivial and wouldn't even allow me to use boost.operators in order to ease my work. Other suggestions?
I do like this:
http://www.boost.org/doc/libs/1_43_0/doc/html/typeof/refe.html#typeof.typo
also:
http://www.boost.org/doc/libs/1_46_0/libs/utility/operators.htm