I\'m trying to implement a hypercubeclass, that is, multidimensional vectors. I have a problem generalizing it. I\'m able to make one for a three dimensional hypercube, but
I would suggest something along those lines:
template class HQ {
std::vector > vector;
public:
HQ(unsigned size) : vector(size,HQ(size)) {}
};
template class HQ {
std::vector vector;
public:
HQ(unsigned size) : vector(size,T()) {}
};
template class HQ {};
You can then implement your accessors for the first both templates as you wish. You can also make things a bit more simple and robust by allowing zero-dimensional matrices:
template class HQ {
std::vector > vector;
public:
HQ(unsigned size) : vector(size,HQ(size)) {}
};
template class HQ {
T data;
public:
HQ(unsigned size) : data() {}
};
I imagine an access operator would look something like this:
template HQ& HQ::operator[](unsigned i) {
return vector[i];
}
template HQ const& HQ::operator[](unsigned i) const {
return vector[i];
}
such that you can write
HQ hq(5);
hq[1][4][2][0] = 77;