Skip to content

Instantly share code, notes, and snippets.

@zironycho
Last active August 22, 2016 04:09
Show Gist options
  • Save zironycho/bed46894b8dcf3fe6de09ca1271a8049 to your computer and use it in GitHub Desktop.
Save zironycho/bed46894b8dcf3fe6de09ca1271a8049 to your computer and use it in GitHub Desktop.
test c++ vector capacity
#include <iostream>
#include <vector>
int main(void) {
std::vector<int> v;
v.resize(10);
std::cout << v.capacity() << std::endl;
v.clear();
std::cout << v.capacity() << std::endl;
v.resize(0);
std::cout << v.capacity() << std::endl;
v.reserve(0);
std::cout << v.capacity() << std::endl;
std::vector<int> v2;
v.swap(v2);
std::cout << v.capacity() << std::endl;
v.resize(10);
v.clear();
v.shrink_to_fit();
std::cout << v.capacity() << std::endl;
v.resize(10);
v = std::vector<int>();
std::cout << v.capacity() << std::endl;
return 0;
}
/*
output with '-std=c++98'
------------------------
10
10
10
10
0
0
10
output with '-std=c++11'
------------------------
10
10
10
10
0
0
0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment