Re: std::vector's reserve(), erase() and clear()
- From: adebaene@xxxxxxxxxxxxxxxx
- Date: 23 Sep 2005 06:36:12 -0700
Alex Vinokur wrote:
> ====== foo.cpp ======
> #include <vector>
> #include <iostream>
> using namespace std;
>
> #define SHOW cout << "capacity = " << v.capacity() << "\t size = " << v.size() << endl;
>
> int main()
> {
> vector<int> v;
> SHOW;
> v.reserve(100);
> SHOW;
> v.resize(100);
> SHOW;
> v.erase(v.end() - 1);
> SHOW;
> v.clear();
> SHOW;
>
> return 0;
>
> }
>
>
> =====================
>
> 1. Output for GNU g++ 3.4.4, GNU gpp 4.0.1, Bolrand C++ 5.5.1, Digital Mars 8.38n
> ---------------------------
> capacity = 0 size = 0
> capacity = 100 size = 0
> capacity = 100 size = 100
> capacity = 100 size = 99
> capacity = 100 size = 0
> ---------------------------
>
> 2. Output for Microsoft C++ 13.00.9466
> ---------------------------
> capacity = 0 size = 0
> capacity = 100 size = 0
> capacity = 100 size = 100
> capacity = 100 size = 99
> capacity = 0 size = 0
> ---------------------------
>
> We can see that capacity == 0 after clear() for Microsoft C++.
> Is it correct behavior?
AFAIK it's unspecified by the standard, so the implementation is free
to do whatever she wants.
Arnaud
MVP - VC
.
- References:
- std::vector's reserve(), erase() and clear()
- From: Alex Vinokur
- std::vector's reserve(), erase() and clear()
- Prev by Date: Re: Windows User Temp Directory
- Next by Date: Re: Control flow hints
- Previous by thread: std::vector's reserve(), erase() and clear()
- Next by thread: pipe buffering
- Index(es):
Relevant Pages
|