I have a function that updates a boost::multi_array which changes size. Is there any way to update an array in a loop (i.e. update it after its initialisation) when it changes size? How can I update (assign) a boost::multi_array after initialisation?
#include <boost/multi_array.hpp>
#include <iostream>
typedef boost::multi_array<int, 2> A;
A update(const A& a) {
auto s = a.shape()[0];
A b{boost::extents[s+s][3]};
auto b_mid = std::copy(a.begin(), a.end(), b.begin());
std::copy(a.begin(), a.end(), b_mid);
return b;
}
int main() {
A a {boost::extents[5][3]};
int r = 5;
while (r--) {
a = // causes error because the size has changed the sizes of RHS and LHS don't match.
update(a); // Alternatively: a = std::move(update(a));
}
}
The problem is that the assignment operator of type A cannot change the size of a multi_array or array. Note that I use C++14. Using std::move() did not help.