I have been wondering about that all day long and I can't find an answer to that specific case.
Main :
std::vector<MyObject*> myVector;
myVector.reserve(5);
myFunction(std::move(myVector));
myFunction :
void myFunction(std::vector<MyObject*> && givenVector){
std::vector<MyObject*> otherVector = givenVector;
std::cout << givenVector[0];
// do some stuff
}
My questions are :
in the main, is
myVector
destroyed by the functionmyFunction()
because it is considered as an rvalue or does the compiler knows that it is also a lvalue and therefore performs a copy before sending it tomyFunction
? What happens if I try to use the vector after the call tomyFunction()
?inside the function
myFunction()
, is the vectorgivenVector
destroyed when affected tootherVector
? if so, what happens when I try to print it ? if not is it useful to use rvalue in this function ?