Your type alias template has exactly the same purpose than a template class, i.e. define a type:
template<typename T, uint32_t H, uint32_t W>
using matrix = std::array<std::array<T, W>, H>;
int main() {
matrix<double, 10,3> m;
return 0;
}
So the good practice would be to handle it exactly as you would do with other type definitions:
- Put it in a header if you intend to reuse this definition in many places (and it seems so for your example, since a matrix is something rather general);
- Embed it in a class (probably in a header) if it's an implementation detail that has not a general purpose;
- Put it in the compilation unit where you use it, if you use your matrix in a single source file.
For non-template type alias, it's the same principle as with the old typedef
, so exactly the same as above, and in addition,
- Put it in a function body, if it has the sole purpose of serving as a very local shortcut for a very long type name.