I have two add
methods, one of them for arithmetic, and one for self-types. Basically, scalar and vector add.
However, I C++ always resolves calls to the vector add method. I don't understand why - specializing the vector-add method with a scalar is invalid. Why does this not invoke SFINAE and simply result in the scalar add being resolved? Is there some way I can fix this?
struct Dimu16
{
quint16 x;
quint16 y;
template<typename To>
Dimu16 operator+( const To a ) const {
return Dimu16{ (quint16)(x+a), (quint16)(y+a) };
}
template<class To>
Dimu16 operator+( To const& o ) const {
static_assert( !std::is_arithmetic<To>::value, "" );
return Dimu16{ (quint16)(x+o.x), (quint16)(y+o.y) };
}
};