Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-90581

Add an uninitialized resize to sequential containers

    XMLWordPrintable

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:

      https://wg21.link/p1072

      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)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes