Re: vector : reserve(LONG_MAX)

From: Peter van Merkerk (merkerk_at_deadspam.com)
Date: 04/22/04


Date: Thu, 22 Apr 2004 16:30:04 +0200


"Alex Vinokur" <alexvn@big.foot.com> wrote in message
news:c68keg$9b16c$1@ID-79865.news.uni-berlin.de...
>
> 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)

If LONG_MAX > std::vector::max_size() with your standard library
implementation it should throw a std::length_error exception.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


Relevant Pages