0

Having a matrix stored in a vector of row-major order, I want to get write access to a column-view (to the corresponding vector entries).

Is it possible to somehow dereference a range-v3 column-view and directly assign the values of another view to it? So far, I found a workaround using zip:view but I am not 100% satisfied with the solution.

wandbox

std::vector<int> mat_as_vec = rv::ints(1, 12 + 1);
auto col_0 = mat_as_vec | rv::drop(0) | rv::stride(3);
auto col_1 = mat_as_vec | rv::drop(1) | rv::stride(3);
auto col_2 = mat_as_vec | rv::drop(2) | rv::stride(3);

//What I want to write is
auto new_col_0 = rv::zip_with([](auto c1, auto c2) {
    return 10 * c1 + c2;
    }, col_1, col_2);
//and then just dereference the view of col_0 and assign the new_col_0 to it
//*col_0 = new_col_0;

//Workaround:
for ( auto [c0, c1, c2] : rs::zip_view(col_0, col_1, col_2) ){
    c0 = 10 * c1 + c2;
}
Barry
  • 286,269
  • 29
  • 621
  • 977
Porsche9II
  • 629
  • 5
  • 17

0 Answers0