#stl
2 posts tagged #stl.
You cannot move out of a priority_queue without a const_cast
priority_queue::top() returns a const reference, so a move-only element cannot be taken out of the queue at all: the copy constructor is selected and the code does not compile. The accepted workaround is a const_cast immediately followed by pop(), which is safe for one specific reason worth understanding before you write it.
std::flat_map is just two vectors
C++23's std::flat_map is an adaptor over a sorted vector of keys and a parallel vector of values. That buys cache-friendly lookups and near-zero memory overhead, and costs O(n) insertion and aggressive iterator invalidation. It replaces std::map, not std::unordered_map, and knowing which vector trick it is tells you exactly when to reach for it.