Is it okay to “Move” an object from a queue, if you’re about to pop from it?

Yes, this is perfectly safe:

std::queue<T> q;
// add stuff...

T top = std::move(q.front());
q.pop();

pop() doesn’t have any preconditions on the first element in the q having a specified state, and since you’re not subsequently using q.front() you don’t have to deal with that object being invalidated any more.

Sounds like a good idea to do!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)