I think another operator* overload should happen, because V cannot be output 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 explicitly specify V , for example, operator*<int, long, long>(...) .
Edit: looking at the signature for operator*(T, matrix<T>) in the second code example, it seems like your first code example 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>) not necessary as a special case.
Casey source share