4 ms·
deque does not move elements once added, so it can’t be implemented like that.
by amluto 2y ago
deque does not move elements once added, so it can’t be implemented like that.
- rowanG077 2y agoIs that an actual guarantee or just the current implementation? I'd expected that at the very least some functions that can operate on std::deque must require moves. erase_if immediately comes to mind.
- dzaima 2y agohttps://en.cppreference.com/w/cpp/container/deque https://en.cppreference.com/w/cpp/container/deque: > When inserting at either end of the deque, references are not invalidated by insert and emplace. > push_front, push_back, emplace_front and emplace_back do not invalidate any references to elements of the deque.
- rowanG077 2y agoThat's a guarantee of some specific operations on deque not a general requirement on the entirety of deque. I looked at your link and erase_if does not have that requirement. So I'd imagine that can and does invalidate references aka move elements.
- dzaima 2y agoRight, indeed, amluto's comment is incorrectly broad. But it's still a thing that a ring buffer cannot guarantee, but std::deque impls must.