I have the Vector ( CVector<T, std::size_t Size>), Matrix ( CMatrix<T, std::size_t Height, std::size_t Width>), and Tensor ( CTensor<T, std::size_t... Sizes>) classes , and I want to be able to implicitly convert from class CTensorto class CVector, if to sizeof...(Sizes) == 1class CMatrix, if sizeof...(Sizes) == 2, therefore, I have the following conversion operators (initially I did not have a template parameter std::enable_ifin in the hope that I can use SFINAE so that it does not compile):
template <typename std::enable_if<sizeof...(Sizes) == 2, int>::type = 0>
operator CMatrix<NumType, Sizes...>() const
{
static_assert(sizeof...(Sizes) == 2, "You can only convert a rank 2 tensor to a matrix");
CMatrix<NumType, Sizes...> matResult;
auto& arrThis = m_numArray;
auto& arrResult = matResult.m_numArray;
concurrency::parallel_for_each( arrResult.extent, [=, &arrThis, &arrResult]( concurrency::index<2> index ) restrict( amp ) {
arrResult[index] = arrThis[index];
} );
return matResult;
}
template <typename std::enable_if<sizeof...(Sizes) == 1, int>::type = 0>
operator CVector<NumType, Sizes...>() const
{
static_assert(sizeof...(Sizes) == 1, "You can only convert a rank 1 tensor to a vector");
CVector<NumType, Sizes...> vecResult;
auto& arrThis = m_numArray;
auto& arrResult = vecResult.m_numArray;
concurrency::parallel_for_each( arrResult.extent, [=, &arrThis, &arrResult]( concurrency::index<1> index ) restrict( amp ) {
arrResult[index] = arrThis[index];
} );
return vecResult;
}
, CTensor<float, 3, 3, 3>, , , , , CMatrix CVector, std::enable_if<false, int>. CTensor 1 2?