Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Order of destruction of container elements (http://www.velocityreviews.com/forums/t730237-order-of-destruction-of-container-elements.html)

Juha Nieminen 08-06-2010 11:55 AM

Order of destruction of container elements
 
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?)

Victor Bazarov 08-06-2010 06:40 PM

Re: Order of destruction of container elements
 
On 8/6/2010 7:55 AM, Juha Nieminen wrote:
> 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
--
I do not respond to top-posted replies, please don't ask

Fraser Ross 08-07-2010 04:44 PM

Re: Order of destruction of container elements
 
"Victor Bazarov"
> On 8/6/2010 7:55 AM, Juha Nieminen wrote:
>> 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



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

Fraser.



Victor Bazarov 08-09-2010 05:01 PM

Re: Order of destruction of container elements
 
On 8/7/2010 12:44 PM, Fraser Ross wrote:
> "Victor Bazarov"
>> On 8/6/2010 7:55 AM, Juha Nieminen wrote:
>>> 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

>
>
> 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
--
I do not respond to top-posted replies, please don't ask

Fraser Ross 08-09-2010 07:17 PM

Re: Order of destruction of container elements
 
>> "Victor Bazarov"
>>> On 8/6/2010 7:55 AM, Juha Nieminen wrote:
>>>> 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

>>
>>
>> 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


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

Fraser.



Öö Tiib 08-09-2010 08:26 PM

Re: Order of destruction of container elements
 
On 9 aug, 22:17, "Fraser Ross" <z...@zzzzzz.com> wrote:
> >> "Victor Bazarov"
> >>> On 8/6/2010 7:55 AM, Juha Nieminen wrote:
> >>>> * * 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

>
> >> 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

>
> 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. ]


Juha Nieminen 08-10-2010 01:54 PM

Re: Order of destruction of container elements
 
Victor Bazarov <v.bazarov@comcast.invalid> wrote:
> 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.)

Victor Bazarov 08-10-2010 02:24 PM

Re: Order of destruction of container elements
 
On 8/10/2010 9:54 AM, Juha Nieminen wrote:
> Victor Bazarov<v.bazarov@comcast.invalid> wrote:
>> 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.)


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
--
I do not respond to top-posted replies, please don't ask


All times are GMT. The time now is 05:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.