我正在尝试编写一些代码,要求我std::array在容器类中有很多s.这些阵列都有不同的大小(如果重要的话,所有阵列都是2-16连续),并且每种大小都有一个.我想将它们放在容器类中,并能够使用模板访问它们.
用代码解释可能更容易.我想要这样的东西:
class ContainerClass {
public:
// I want to declare some number of arrays right here, all of different
// sizes, ranging from 2-16. I'd like to be able to access them as
// arr<2> through arr<16>.
// This code gives a compiler error, understandably.
// But this is what I'd think it'd look like.
template <size_t N> // I also need to find a way to restrict N to 2 through 16.
std::array<int, N> arr;
// …Run Code Online (Sandbox Code Playgroud)