Says I have a class with a standard container:
class Library{
std::vector<Book> books;
public:
void putOnFire(){
books.clear();
}
};
The usual way to clear a container is "clear", however most code is not "STL compliant" so many containers (by third parties) may not have a "clear" method. however, If they have move semantics I could just use std::move right?
void putOnFire(){
auto p = std::move(books); //books cleared when p out of scope
}
this is to write most generic possible code that works also with something that is not a STL container with a "clear" method.
std::move
leaves the moved-from object in a valid but unspecified state. In particular it might stay exactly the way it was before, so while this might actually work with your implementation of the stl, it will certainly not work for all third-party containers. (And might break at any point in the future when your implementation of the stl changes due to an update)