开发者

STL containers element destruction order

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜