Alex B
Alex B

Reputation: 84822

STL containers element destruction order

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

Upvotes: 29

Views: 2923

Answers (2)

Roger Pate
Roger Pate

Reputation:

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

Upvotes: 25

Terry Mahaffey
Terry Mahaffey

Reputation: 11981

  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.

Upvotes: 5

Related Questions