I found the following code here:
template <typename T>
//some code here
std::queue<T> search_queue;
std::unordered_set<T> searched;
while (!search_queue.empty()) {
T& person = search_queue.front(); // 'T& person' is what I'm particularly interested about.
search_queue.pop();
// some code here
if (searched.find(person) == searched.end()) {
// some code here
}
}
Since std::queue acts as a wrapper to the underlying container, which, in our case, is std::deque we find the following about std::deque's pop_front:
Iterators and references to the erased element are invalidated.
Hence, T& person must be a mistake, because the element it refers to is erased immediately after the reference is created.
Is it so?
Thanks.