GCC warns that these types are not trivally copyable so we should not use
std::memmove. We cannot use std::move either since the beginning of the new
range may intersect the old range. Hence: use std::move_backward to copy from
the end, which cannot overlap.
// at least one element when we get here, subtracting 1 works fine.
data.resize(2*data.size());
for (size_type i=individual_size.size()-1; i>0; --i)
- std::memmove(&data[i*row_length*2], &data[i*row_length],
- individual_size[i]*
- sizeof(std::pair<size_type,double>));
+ {
+ const auto ptr = data.data();
+ std::move_backward(ptr + i*row_length,
+ ptr + i*row_length + individual_size[i],
+ ptr + i*2*row_length + individual_size[i]);
+ }
row_length *= 2;
}
data[index*row_length+my_length] = pair;
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams