Order of destruction of container elements

J

Juha Nieminen

What does the C++ standard say about the order in which elements in
a STL container are destroyed?

(IIRC, arrays are guaranteed to be constructed in order of increasing
indices and destroyed in the reverse order, but what about STL containers?)
 
V

Victor Bazarov

What does the C++ standard say about the order in which elements in
a STL container are destroyed?

(IIRC, arrays are guaranteed to be constructed in order of increasing
indices and destroyed in the reverse order, but what about STL containers?)

AFAICT, it's not specified.

V
 
V

Victor Bazarov

"Victor Bazarov"


Are you saying that it isn't specified for arrays too?

No, that's not what I'm saying. The question was about STL containers,
and I took it to be about Standard containers. The Standard document
contains no mention of the order of destruction of the elements of any
of the standard containers.

V
 
F

Fraser Ross

"Victor Bazarov"
No, that's not what I'm saying. The question was about STL
containers, and I took it to be about Standard containers. The
Standard document contains no mention of the order of destruction of
the elements of any of the standard containers.

V

I'm wondering if its specified for arrays. I don't think it is.

Fraser.
 
Ö

Öö Tiib

I'm wondering if its specified for arrays.  I don't think it is.

Fraser.

It is specified for arrays in what order constructors/destructors for
elements of "T t[3][5];" are called:

[12.6/3]
When an array of class objects is initialized (either explicitly or
implicitly), the constructor shall be called for each element of the
array, following the subscript order; see 8.3.4. [Note: destructors
for the array elements are called in reverse order of their
construction. ]
 
J

Juha Nieminen

Victor Bazarov said:
The Standard document
contains no mention of the order of destruction of the elements of any
of the standard containers.

Shouldn't this omission be fixed? It should at the very least have a
sentence stating that the order of destruction is implementation-dependant.
(Of course saying nothing at all about the subject kind of implies the
same thing, but a standard should be as unambiguous as possible and not
leave things completely unspecified.)
 
V

Victor Bazarov

Shouldn't this omission be fixed? It should at the very least have a
sentence stating that the order of destruction is implementation-dependant.
(Of course saying nothing at all about the subject kind of implies the
same thing, but a standard should be as unambiguous as possible and not
leave things completely unspecified.)

Saying that it is "implementation-dependent" will probably mean that the
implementation has to document that. If nothing is said, nothing needs
to be documented... :)

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top