Is it possible to get a sparse (non-contiguous) subset of references to array elements?
Suppose I have array a = [1,4,5]
and indices pos = [0,1]
. I would like to get b = [1,5]
without copying elements from a
. In other words, I would like to slice into a
and create a view called b
.
The following errors since "expression is not assignable":
#include <array>
int main() {
std::array<double,3> a = {1, 4, 5};
std::array<double, 2> b;
int c = 0;
int pos[2] = {0,2};
for (auto i = a.begin(); i != a.end(); i++) {
&b[c] = i;
i++;
}
return 0;
}