Re: vector : reserve(LONG_MAX)

From: Pete Becker (petebecker_at_acm.org)
Date: 04/22/04


Date: Thu, 22 Apr 2004 10:33:15 -0400

Alex Vinokur wrote:
>
> Method vector.reserve() returns no value.
> How can we prevent the following situation?
>
> ====== foo.cpp ======
> #include <climits>
> #include <vector>
> #include <iostream>
> using namespace std;
>
> int main()
> {
> vector<int> v (100e);
> cout << v.capacity() << endl;
> v.reserve(LONG_MAX);
> cout << v.capacity() << endl;
> return 0;
> }
> =====================
>
> ====== Compilation & Run ======
>
> $ g++ -v
> [---omitted---]
> gcc version 3.3.1 (cygming special)
>
> $ g++ -W -Wall foo.cpp
>
> $ a
> 100
> Aborted (core dumped)
>
> ===============================
>

Catch the exception.

-- 
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)


Relevant Pages