I would like to have array-like objects that support multiple arrays pointing to the same memory region. Something that would look like this with good old raw pointers:
#include <iostream>
int main()
{
double* array{new double[100]};
double* subarray{array + 5};
std::cout << array[5] << std::endl;
subarray[0] = 33.0;
std::cout << array[5] << std::endl;
delete[] array;
return 0;
}
Something that would look like
Foo array{100, 3.0};
Foo subarray{array.slice(40,50)};
assert(&array[43] == &subarray[3]);
As far as I see, things like std::vector
and std::valarray
would required copying the subsection into a new object, which is not what I want. I could not find anything else. I am happy to implement my own solution, but is there anything I could use?