I am trying to customize my template creation skills (I know very little) by creating a library containing matrices and operations on these matrices. Basically, I want my matrix to be very strongly typed (data type and size known at compile time), and I also want to be able to automatically subtract the type of transpose matrix.
template< typename TDataType, size_t rows, size_t cols > class MyMatrix
Matrices can be nested, therefore it TDataTypecan be an integral type, but also MyMatrix<...>, forcing the data type for the transposed matrix to be not necessarily the same as the original matrix, for example:
Transpose( MyMatrix< MyMatrix< char, 2, 3 >, 4, 6 > ) ==> MyMatrix< MyMatrix< char, 3, 2 >, 6, 4 >(the data type of the external matrix has changed)
My first attempt at swapping with a transpose type:
template< typename TDataType >
struct Transpose
{
typedef TDataType type;
};
template<>
struct Transpose< MyMatrix<TDataType, rows, cols> >
{
typedef MyMatrix<typename Transpose<TDataType>::type, cols, rows> type;
};
, Transpose-template MyMatrix ( TDataType).
, ( , ):
template< typename TMatrixType, typename TDataType, size_t rows, size_t cols >
struct Transpose
{
typedef TMatrixType type;
};
template< typename TDataType, size_t rows, size_t cols >
struct Transpose< MyMatrix<TDataType, rows, cols>, TDataType, rows, cols >
{
typedef MyMatrix< typename Transpose<TDataType,TDataType,rows,cols>::type, cols, rows > type;
};
, ; , ?
( , , - ). !
@Bo Persson @Will A: , ( ) , , , (, - 32- ) . , , , , , , , ( , ").
@Bo Perrson: , , , , . , MyMatrix , - Transpose-struct.
@VJo: , . T MyMatrix <... > , Transpose<T> , T. (char, int, double...) , , .