STL容器元素销毁顺序 [英] STL containers element destruction order

查看:113
本文介绍了STL容器元素销毁顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ISO C ++标准是否要求对STL容器内的对象执行任何形式的销毁顺序?

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

  • std::list/std::vector/std::map元素是否从容器的开头或结尾开始被破坏?
  • 我可以依靠std::map在内部将其元素存储在std::pair中,以便在键对中的键在其值之前被销毁(反之亦然)吗?
  • 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. 标准中未指定.
  2. 是的,但这意味着密钥在 关联值之后被销毁.
  1. Unspecified in the standard.
  2. Yes, but this means that the key is destroyed after its associated value.

这篇关于STL容器元素销毁顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆