Google has proposed adding precise growth to std::string on with the benefit that it saves quite a bit of memory and time you the string isn't being repeatedly appended. However, the project rejected the idea.
[0] https://github.com/facebook/folly/blob/3c8829785e3ce86cb821c...
https://github.com/abseil/abseil-cpp/blob/master/absl/string...
The standard adopted it as resize_and_overwrite. Which I think is a little clunky.
What would be the practical difference to std::string::reserve?
string s;
s.reserve(50);
char * p = s.data(); // ok so far
s.reserve(100); // now p may be invalidI guess the idea of uninitialized resize is that you reserve the space, bump the size, and then you can directly set the new members with operator[]. If your input data is not contiguous, and would need to use push_back() otherwise, you can save a few if-checks. But that's pretty much it, I assume.
s.reserve(n); // precise allocation.
s.resize(n); // doesn't grow.
or s.reserve(n);
s.append(....); // a fairly robust set of overloads.
That being said... I completely agree that imprecise resize() is unfortunate, and unexpected. I'm going to have to keep an eye out for how I use resize() going forward. (Not a lot, admittedly).