I
I
iihaarr2022-04-05 16:52:32
C++ / C#
iihaarr, 2022-04-05 16:52:32

How to compare 2 classes with different template parameters?

There is a matrix class:

template<const std::size_t rows, const std::size_t columns, typename T = int>
class Matrix 
{
    using type = T;

    static constexpr std::size_t m_Columns = columns;
    static constexpr std::size_t m_Rows = rows;
    std::array<std::array<T, columns>, rows> m_Matrix;
}

I'm trying to write a matrix multiplication function. To do this, it is necessary to check the correctness of the dimension of the matrix and the type of its values. First I tried to check the type:
template<typename M, typename std::enable_if<std::is_same<T, typename M::type>::value>::type = true>

But this code gives an error: a non-type template parameter cannot have type
Something like what I want to see
template<typename M, typename std::enable_if<std::is_same<T, typename M::type>::value>::type = true && столбцы м1 = строкам м2>
Matrix<rows, M::m_Columns, T> MultiplyOnMatrix(const M& matrix)

How can this be done through templates?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-04-05
@iihaarr

Isn't it easier that way?

template <const std::size_t other_columns>
 Matrix<rows, other_columns, T> MultiplyOnMatrix(const Matrix<columns, other_columns, T>& matrix)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question