Skip to content

Instantly share code, notes, and snippets.

@onqtam
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onqtam/9095763 to your computer and use it in GitHub Desktop.
Save onqtam/9095763 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
using namespace std;
int main() {
{
size_t cap = 0;
vector<int> v;
for(int i = 0; i < 20; i++) {
v.reserve(v.capacity() + 1);
cap = v.capacity();
cout << cap << endl;
}
}
cout << endl;
{
size_t cap = 0;
vector<int> v;
for(int i = 0; i < 20; i++) {
v.push_back(1);
cap = v.capacity();
cout << cap << endl;
}
}
cout << endl;
{
size_t cap = 0;
vector<int> v;
for(int i = 0; i < 20; i++) {
v.resize(v.size() + 1);
cap = v.capacity();
cout << cap << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment