#include <iostream>
#include <vector>
struct MyType {};
int main()
{
const int NumberToPushBack = 10000;
std::vector<MyType> array;
int numberOfReallocations = 0;
for(int i = 0; i < NumberToPushBack; ++i)
{
size_t oldSize = array.capacity();
array.push_back(MyType());
if(oldSize != array.capacity())
++numberOfReallocations;
}
std::cout << "In " << NumberToPushBack << " push_backs, there were only " << numberOfReallocations << " reallocations of the buffer." << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKc3RydWN0IE15VHlwZSB7fTsKCmludCBtYWluKCkKewoJY29uc3QgaW50IE51bWJlclRvUHVzaEJhY2sgPSAxMDAwMDsKCQoJc3RkOjp2ZWN0b3I8TXlUeXBlPiBhcnJheTsKCWludCBudW1iZXJPZlJlYWxsb2NhdGlvbnMgPSAwOwoJCglmb3IoaW50IGkgPSAwOyBpIDwgTnVtYmVyVG9QdXNoQmFjazsgKytpKQoJewoJCXNpemVfdCBvbGRTaXplID0gYXJyYXkuY2FwYWNpdHkoKTsKCQlhcnJheS5wdXNoX2JhY2soTXlUeXBlKCkpOwoJCQoJCWlmKG9sZFNpemUgIT0gYXJyYXkuY2FwYWNpdHkoKSkKCQkJKytudW1iZXJPZlJlYWxsb2NhdGlvbnM7Cgl9CgkKCXN0ZDo6Y291dCA8PCAiSW4gIiA8PCBOdW1iZXJUb1B1c2hCYWNrIDw8ICIgcHVzaF9iYWNrcywgdGhlcmUgd2VyZSBvbmx5ICIgPDwgbnVtYmVyT2ZSZWFsbG9jYXRpb25zIDw8ICIgcmVhbGxvY2F0aW9ucyBvZiB0aGUgYnVmZmVyLiIgPDwgc3RkOjplbmRsOwoJCglyZXR1cm4gMDsKfQ==