As a specific subcase of these two questions:
Is a moved-from vector always empty?
What can I do with a moved-from object?
one wonders: Is it legal to call .clear()
, .chrink_to_fit()
, .empty()
on a moved-from std::vector
before assigning a new vector to it? I could ask about push_back()
but I don't know what that would give, since it's not safe to rely on a moved from vector being empty.
What is clear is that destruction, as well as assignment from a new vector is legal.
std::vector<int> fs = getVec();
giveVecs(std::move(fs));
fs.empty(); // 1.?
fs.size(); // 2.?
fs.shrink_to_fit(); // 3.?
fs.clear(); // //4. ?
fs = {} ; // 5. Should be fine, but weird when we have .clear()
fs.push_back(1); //
Edit:
I should clarify, that some operations do have preconditions: Therefore, (as you can read in the other questions), not All operations are legal after a move.
My question can therefore be restated like this: Are there any preconditions on either of the three operations? One source of problems could be fine print related to the allocator of the moved from object.