I am trying to implement a multi dimensional array for educational(personal, this is not an assignment) purposes and am trying to implement the underlying data as a single dimensional array. I know that in order to translate a index I need to use either row major or column major formula but I cannot figure out how to do this using template folding (looks impossible via online) so I was wondering how I could go about trying this.
for reference:
struct array_impl<T, std::index_sequence<dimensions...>> {
template <typename Type, auto>
using id = Type;
T& operator[](id<std::size_t, dimensions>... idx) {
// How do I compare each value in idx to the appropriate value in dimensions?
}
}
Row Major formula:
// (i1 to in): Array[i1][i2]...[in] = (i1 * s2 * ... * s(n - 1) * sn + i2 * ... * s(n - 1) * sn + ... + i(n - 1) * sn + in)
Where i is an index to grab within a dimension and s is the maximum size of that dimensions