<us******@gmail.com> wrote in message news:11**********************@g14g2000cwa.googlegr oups.com...
Alex Vinokur ??:
What is relation between std::vector's reserve() and erase()/clear()?
[snip]
you can test it on you computer,it's easy!
====== 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?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn