开发者

STL containers element destruction order

开发者 https://www.devze.com 2022-12-16 21:38 出处:网络
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 cont

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 e开发者_StackOverflow社区lements in std::pairs internally so a key in a pair is destroyed before its value (or vice versa)?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消