Changeset 1919


Ignore:
Timestamp:
Sep 16, 2012, 6:48:14 PM (7 years ago)
Author:
sam
Message:

core: implement Array::Resize() to forcibly set the size of an array.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/array.h

    r1818 r1919  
    158158    void Remove(int pos, int todelete = 1)
    159159    {
     160        /* FIXME: we need to call dtors for the first
     161         * todelete elements here */
    160162        for (int i = pos; i + todelete < m_count; i++)
    161163            m_data[i] = m_data[i + todelete];
     
    163165            m_data[i].~Element();
    164166        m_count -= todelete;
     167    }
     168
     169    void Resize(int count, Element e = Element())
     170    {
     171        Reserve(count);
     172
     173        /* Too many elements? Remove them. */
     174        for (int i = count; i < m_count; ++i)
     175            m_data[i].~Element();
     176
     177        /* Not enough elements? Add some. */
     178        for (int i = m_count; i < count; ++i)
     179            m_data[i] = e;
     180
     181        m_count = count;
    165182    }
    166183
Note: See TracChangeset for help on using the changeset viewer.