Opened 5 years ago

Closed 5 years ago

#15195 closed defect (fixed)

wxArray.resize() inconsistency

Reported by: troelsk Owned by:
Priority: low Milestone:
Component: base Version: stable-latest
Keywords: wxArray wxArrayInt simple Cc:
Blocked By: Blocking:
Patch: yes


The doc says that wxArray::SetCount() never shrinks the array. This is true, also for wxArray::resize(). But resize() you expect to behave as std::vector. And if building wx with wxUSE_STL, then resize() will happily shrink.
I suggest resize() being reimplemented to do as STL always, regardless of the wxUSE_STL flag, while preserving the SetCount() behaviour (in !wxUSE_STL mode at least)

    std::vector<int> vector;
    wxASSERT(vector.size() == 2);

    wxArrayInt array;
    array.resize(2); // doing nothing if !wxUSE_STL
    wxASSERT(array.size() == 2); // asserts if !wxUSE_STL

"If the array has already count or more items, nothing is done"

Attachments (1)

resize.patch download (1.2 KB) - added by troelsk 5 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 5 years ago by vadz

  • Keywords simple added
  • Priority changed from normal to low
  • Status changed from new to confirmed

Yes, I agree, resize() should always do what it does while SetCount() shouldn't be changed for compatibility (there i also Shrink() that can be used to resize to the size lesser than current one in wxArray).

Changed 5 years ago by troelsk

comment:2 Changed 5 years ago by troelsk

  • Patch set

Added patch

comment:3 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [73986]) Allow shrinking the array with wxArray::resize().

This method did nothing if its argument was less than the current array size,
as it was just a synonym for SetSize() which was documented to behave like
this, but this was inconsistent with std::vector and wxVector resize() which
does shrink the array, so change wxArray version to shrink it too.

Closes #15195.

Note: See TracTickets for help on using tickets.