Is it safe to store a pointer to an item in an std::set?
This question already has an answer here:
Yes, both set
and unordered_set
are safe in this regard. If references are not invalidated, your pointers also remain valid.
It's an easy property for the node-based collections to maintain; unlike vector
there's no need for them to move values around in memory.
上一篇: 保留单独的指向容器项目的指针