Changeset 1203


Ignore:
Timestamp:
Aug 14, 2003, 9:24:47 AM (17 years ago)
Author:
sveta
Message:
  • Old version (with decrease and expand).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/libp++/pxx_vector.ih

    r1191 r1203  
    6868
    6969template <typename type_t>
     70void Vector<type_t>::decrease (size_t _extra)
     71{
     72  size_t i;
     73  if (_extra > length) {
     74    for ( i = 0; i < length; i++)
     75      (data + i)-> ~type_t();
     76    length = 0;
     77  } else {
     78    for ( i = length - _extra; i < length; i++)
     79      (data + i)-> ~type_t();
     80    length -= _extra;
     81  }
     82}
     83
     84template <typename type_t>
    7085void Vector<type_t>::expand (size_t _extra)
    7186{
     
    99114type_t& Vector<type_t>::operator [] (size_t _index)
    100115{
    101   if (_index >= length) expand(_index - length + 1);
    102   return data[_index];
     116  if (_index < length) {
     117    return data[_index];
     118  } else {
     119    throw OutOfRange();
     120  }
    103121}
    104122
Note: See TracChangeset for help on using the changeset viewer.