If I have a container and call clear() on it, does that just destruct all of the elements inside or does it actually free/allocate new memory internally too? Is this behavior outside the scope of the C++ standard?
This boils down to:
unordered_set<int> mySet { 1, 2, 3, 4, 5 };
mySet.reserve(1000);
mySet.clear();
//Is this pointless/redundant
//or should I treat my container like it was just constructed?
mySet.reserve(1000);
A quick test on ideone (http://ift.tt/1CmeXQJ) shows that the internal memory buffer is retained after a call to clear. So, at least for new versions of g++ on unordered_set that is the case. My question goes to 1) what the standard says, if anything and 2) whether this behavior is consistent across all containers.
Aucun commentaire:
Enregistrer un commentaire