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 instd::pair
s internally so a key in a pair is destroyed before its value (or vice versa)?
- Unspecified in the standard.
- Yes, but this means that the key is destroyed after its associated value.
- Unspecified
- 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.
精彩评论