#include <vector>
struct A { int a[100]; };
void foo (const A& a) {
std::vector<A> vA;
vA.push_back(std::move(a)); // how does move really happen?
}
int main () {
A a;
foo(a);
}
The above code compiles fine. Now everywhere it's written that move
avoids copying.
Following are my queries:
- Does the
move
really work when one deals with a lvalue [non]-const
reference? - Even with "rvalue reference", how is the copy avoided when the object is inserted into a standard container like above?
e.g.
void foo (A&& a) { // suppose we invoke this version
std::vector<A> vA;
vA.push_back(std::move(a)); // how copy is avoided?
}