Topic: STL vector class


Author: john@sg25.aud.temple.edu (John W. Schwegler)
Date: 1996/10/01
Raw View
I've been using the ObjectSpace implementation of the STL on
SGI IRIX 5.3 for a while now, and I ran into something of an
inconvenience recently.  The vector<> class allows you to specify
an initial size for a vector, and also has a reserve() member
to reserve storage up to a particular size.  However, it has no
resize() member, to change the size of actual vector.

Is there some particular reason this was never done?
I had to rewrite a resize function that does an insert()
call with a temporary default-constructed object to extend the vector.

Resizing to shorten the vector would require erasing a number
of object off the back end of the vector.  It seems to me that
this would be a relatively common operation.  Is there any reason
it hasn't been included?

-john
--
______________________________________________________________________________
"Genius may have its limitations,       | John Schwegler
   but stupidity is not thus            | Temple U. Auditory Research Dept.
   handicapped."                        | john@flower.aud.temple.edu
         - Elbert Hubbard               | (215) 707-3687 FAX 707-3650
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: jbc@ElSegundoCA.NCR.COM (Jim Chapman)
Date: 1996/10/02
Raw View
In article dpi@cronkite.ocis.temple.edu, john@sg25.aud.temple.edu (John W. Schwegler) writes:
> I've been using the ObjectSpace implementation of the STL on
> SGI IRIX 5.3 for a while now, and I ran into something of an
> inconvenience recently.  The vector<> class allows you to specify
> an initial size for a vector, and also has a reserve() member
> to reserve storage up to a particular size.  However, it has no
> resize() member, to change the size of actual vector.
>
> Is there some particular reason this was never done?
> I had to rewrite a resize function that does an insert()
> call with a temporary default-constructed object to extend the vector.
>
> Resizing to shorten the vector would require erasing a number
> of object off the back end of the vector.  It seems to me that
> this would be a relatively common operation.  Is there any reason
> it hasn't been included?
>

Possibly because it's not needed.  The push_back() and insert() methods
automatically acquire a larger storage area if needed.  Use pop_back()
or erase(iterator first, iterator last) to remove objects from the end
of a vector.

---
---------------
Jim Chapman                        NCR Corporation
jbc@ElSegundoCA.NCR.COM            Parallel Systems Division
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]