Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
To complement resize(), which (when growing) value-initializes the objects, add constructors and resize-like methods that "don't initialize".
How to "not initialize"
Default construction
The straightforward way is to default construct elements in the container, not value construct them. However, such a thing won't give benefits for Qt types which always initialize when default constructed...
Qt::Uninitialized
Many Qt types have a constructor taking a Qt::Uninitalized argument. So, if the type is constructible using that, we should definitely use it.
Not constructed at all
Not a fan of this, at least, not through resize() methods – having objects around for which lifetime hasn't started yet is tricky to manage (they can't be merely overwritten via assignments).
What kind of API to offer
uninitializedResize(m) / resizeUninitialized
(Subject to the usual bikeshedding on the name). If n < size() then they erase from the end, as usual. If n > size(), reallocate if necessary and construct the n-size() elements at the end as specified above. So this is mostly like resize(), it just changes what happens when growing.
Resize for overwrite
P1072 is also proposing a different API, resizing AND delegating initialization to a function called from within the resizing:
I wonder how actually practical it is, or if it's a boring "settling for a compromise" to actually achieve Standardizataion...
Bonus points: fix QByteArray / QString
Stop making QByteArray::resize() / QString::resize() not initialize their data, unlike any other resize() method. (They should still NUL terminate it, that's another story)