Say I have the following scenario:
std::vector<std::vector<double>> v(6, std::vector<double>(6, 0.0));
std::vector<std::vector<double>> y;
for (const std::vector<double> &p : v) {
y.push_back(p);
}
It makes a deep copy vin y. Is there any way to do this using std::copyin vector 2D.
std::copy(v.begin(), v.end(), y.begin())
will not work. For bonus points, can this be expanded to a vector ND? This seems important to avoid the following loops that would be Ndeep:
...
for (const std::vector<std::vector<<double>> &p : v) {
for (const std::vector<double> &q : p) {
...
I know that performance is reasonable, there is no difference since it is implemented std::copy. Just interesting from the point of view of compactness of the code.
source
share