Created
October 15, 2019 22:20
-
-
Save SavchenkoValeriy/978576a37c9b56a0a3320aa4c15227ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T, unsigned N> | |
struct MatrixImpl { | |
static_assert(N > 0, "Matrix should have at least one dimension"); | |
using Type = std::vector<typename MatrixImpl<T, N - 1>::Type>; | |
}; | |
template <typename T> | |
struct MatrixImpl<T, 1> { | |
using Type = std::vector<T>; | |
}; | |
template <typename T, unsigned N> | |
using Matrix = typename MatrixImpl<T, N>::Type; | |
template <typename T> | |
auto createMatrix(T defaultValue) { | |
return defaultValue; | |
} | |
template <typename T, typename... Rest> | |
auto createMatrix(T defaultValue, unsigned N, | |
Rest... Dimensions) { | |
return Matrix<T, sizeof...(Rest) + 1>( | |
N, createMatrix<T>(defaultValue, Dimensions...) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment