I think there must be a another overload of operator*
involved, because V
cannot be deduced given the declaration:
template<class T, class U, class V>
auto operator*(const T a, const matrix<U> A)
-> decltype(std::declval<T>()*std::declval<U>());
The only way to call this function is to specify V
explicitly, e.g., operator*<int, long, long>(...)
.
Edit: Looking at the signature for operator*(T, matrix<T>)
in the second code example, it would appear that your first code sample should read:
template<class T, class U>
auto operator*(const T a, const matrix<U>& A) -> matrix<decltype(a*A(0,0))>
{
matrix<decltype(a*A(0,0))> B(A.size(1),A.size(2));
for(int ii = 0; ii < B.size(1); ii++)
{
for(int jj = 0; jj < B.size(2); jj++)
{
B(ii,jj) = a*A(ii,jj);
}
}
return B;
}
operator*(T,matrix<T>)
should not be necessary as a special case.