Last active
August 22, 2016 04:09
-
-
Save zironycho/bed46894b8dcf3fe6de09ca1271a8049 to your computer and use it in GitHub Desktop.
test c++ vector capacity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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