Skip to content

Template Aliases

Template Aliases

A type alias is a name that refers to a previously defined type. Alias template is a name that refers to a family of types.

1
2
template <class T, size_t N_ROWS, size_t N_COLUMNS>
using matrix = std::array<std::array<T, N_COLUMNS>, N_ROWS>;

1
2
3
4
5
6
7
matrix<double, 10, 3> m;
double i = 5.6;
for (auto &row : m) {
    for (auto &xij : row) {
        xij = i++;
    }
}

1
2
3
4
5
for (auto &row : m) {
    for (auto &xij : row) {
        std::cout << "xij: " << xij << '\n';
    }
}

Share Snippets