Is it safe to store a pointer to an item in an std::set?

This question already has an answer here:

  • Iterator invalidation rules 4 answers

  • 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.

    链接地址: http://www.djcxy.com/p/73338.html

    上一篇: 保留单独的指向容器项目的指针

    下一篇: 将指针存储在std :: set中安全吗?