Consider the following C++ code example:
int array_1[] = {5,6,7};
int array_2[] = {6,7,8,9};
int array_3[] = {2,3};
int* meta_array[] = {array_1, array_2, array3};
Now I want to iterate over all of the elements in the sub arrays of meta_array without causing a seg fault.
The problem, of course, is that I have no way to get the size of the arrays to avoid overstepping their bounds.
I can do sizeof array_1 / sizeof array_1[0] to get the size of a common 1-dimensional array pretty quickly, but once I’m in the meta_array, every element has been converted to a pointer, and so sizeof will return the byte size of the pointer instead of the entire array. Thus, sizeof meta_array[0] / sizeof meta_array[0][0] doesn’t really do much to help my cause.
Is there a standard solution to iterating over nonuniform multidimensional arrays out there already, or should I just go ahead and use std::vector?
use
std::vector.or, use a “closing” number but you must be sure there will be no elements with that value, ever.