I have some questions when I read some open source codes like
struct A {
int a;
};
class C {
private:
std::queue<A> q;
public:
C() {
q.emplace(1);
q.emplace(2);
}
A pop1() {
auto a = std::move(q.front());
q.pop();
return a;
}
void pop2(A&& pData) {
pData = std::move(q.front());
q.pop();
}
A pop3() {
auto &a = q.front();
q.pop();
return a;
}
};
I wonder whether move
is useful in this situation(to achieve its goal to be effcient by saving copy construct).
And pop3
is my version, and I think it may be more effcient by saving the move construct if using pop1
.