#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

Description

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;
    vector.resize(5);
    vector.resize(2);
    wxASSERT(vector.size() == 2);

    wxArrayInt array;
    array.resize(5);
    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"
http://docs.wxwidgets.org/2.8/wx_wxarray.html#wxarraysetcount

Attachments (1)

resize.patch download (1.2 KB) - added by troelsk 19 months ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 19 months 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 19 months ago by troelsk

comment:2 Changed 19 months ago by troelsk

  • Patch set

Added patch

comment:3 Changed 19 months 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.