std::move: What happens with old object reference?

1
2
3
4
5
6
7
8
9
#include <utility>
#include <vector>

int main()
{
    std::vector<int> v_old = { 1,2,3 };
    std::vector<int> v_new = std::move( v );
    // What state has now v_old? Is it still accessible?
}


I need to move the content of a std::vector to another vector and want to use the old vector at an empty state. Is accessing the old vector after a move still valid?
Last edited on
Yes the old vector will be valid but in an unspecified state. See:

http://www.cplusplus.com/reference/utility/move/?kw=move

v_old is supposed to be empty. You may ensure it when you call clear().
Topic archived. No new replies allowed.