Suppose I have the following code:
#include <vector>
struct A {
int a;
int x;
};
int main() {
using namespace std;
A a1;
A a2;
vector<A> va;
va.push_back(a1);
va.push_back(move(a2));
}
I am aware that the elements of std::vector are stored contiguously, unlike a std::list. In the above code a2
is moved but is there really no copying of a2
to the vector va
? What is the difference between va.push_back(a2);
and va.push_back(move(a2));
?