r/cpp • • Jan 02 '26

Every LLM hallucinates that std::vector deletes elements in a LIFO order

251 Upvotes

118 comments sorted by

View all comments

Show parent comment

2

u/NotMyRealNameObv Jan 03 '26

Why on earth would the standard be expected to define the exact order that elements in a vector are destroyed?

5

u/The_JSQuareD Jan 03 '26 edited Jan 03 '26

To... standardize behaviors.

Or to give you a less glib answer: the standard defines the order destructors run in when you call delete[]. It is reasonable to expect that it would also define it for the most common library wrapper around a dynamic array.