STL containers element destruction order

笑着哭i 提交于 2019-12-28 02:09:04

问题


Does ISO C++ standard mandate any sort of destruction order of objects inside STL containers?

  • Are std::list/std::vector/std::map elements destroyed starting from the beginning or the end of the container?
  • Can I rely on std::map storing its elements in std::pairs internally so a key in a pair is destroyed before its value (or vice versa)?

回答1:


  1. Unspecified in the standard.
  2. Yes, but this means that the key is destroyed after its associated value.



回答2:


  1. Unspecified
  2. Yes, you can depend on std::map storing it's elements in std::pairs, but I don't see anything which specifies the Key portion of a std::pair being destructed before a Value portion.


来源:https://stackoverflow.com/questions/2083603/stl-containers-element-destruction-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!