Is there a STL container (no Boost) from which an element can removed and moved to an lvalue?
Say I have a std::vector of large objects and a variable to which I want to pop an element from the vector.
var = vec.back(); // non-move assign op vec.pop_back(); // dtor var = containerWithMovePop.pop_and_return(); // move assign-op It's not like performance is so important, I just want to know if it's possible.
var = std::move(vec.back()); vec.pop_back();?vec.back()be in between the two operations? Not valid I'd say, is that correct?moveis required to leave the object in a state that's valid to at least some degree, so you can still (at least) destroy it, which is all you're doing here. I believe you should be fine as long as you don't try to interleave any other use of the vector's data between the move and the pop_back.