3 ms·
Rust rejects this because it isn’t necessarily safe. The Rust deque grows when it needs to, reallocating and copying all the old elements over to the new locati
by vlmutolo 6y ago
Rust rejects this because it isn’t necessarily safe. The Rust deque grows when it needs to, reallocating and copying all the old elements over to the new location, and then freeing the old location.
If push_back triggers this reallocation, then you get UB here.
So either the C++ deque doesn’t offer the same functionality, or it isn’t actually safe.
- millstone 6y agoThe C++ standard requires this to be safe. Internally deque is implemented as a vector of fixed-size blocks. Pushing an element may allocate a new block but will not deallocate an existing one.