There are several ways to make a vector empty, including
std::vector<int> example = makeMyReallyBigVector();
example.clear();
example.resize(0);
example.erase(example::being(), example::end());
// any other method which would be relevant
Are there any guarantees in the C++ standard about which is most efficient, time-wise? The contents are a primitive data type without destructor. What I am especially concerned about is, I don't want the vector capacity to change, I just want it's internal "used size" set to 0 without touching the now-erased contents.
What I want is to set the int vector size to 0 in constant time, without freeing any memory. Is this possible with C++ standard?
If the C++ standard gives no guarantees, I'm using GNU C++ standard library, so if standard doesn't, does that give any guarantees? For sake of portability, in this case also information about the Clang and Microsoft standard libraries would of interest, of course.