Order of destruction of container elements

Discussion in 'C++' started by Juha Nieminen, Aug 6, 2010.

  1. 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?)
     
    Juha Nieminen, Aug 6, 2010
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Aug 6, 2010
    #2
    1. Advertising

  3. Juha Nieminen

    Fraser Ross Guest

    "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.
     
    Fraser Ross, Aug 7, 2010
    #3
  4. 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
     
    Victor Bazarov, Aug 9, 2010
    #4
  5. Juha Nieminen

    Fraser Ross Guest

    >> "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.
     
    Fraser Ross, Aug 9, 2010
    #5
  6. Juha Nieminen

    Öö Tiib Guest

    On 9 aug, 22:17, "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'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. ]
     
    Öö Tiib, Aug 9, 2010
    #6
  7. Victor Bazarov <> 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.)
     
    Juha Nieminen, Aug 10, 2010
    #7
  8. On 8/10/2010 9:54 AM, Juha Nieminen wrote:
    > Victor Bazarov<> 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
     
    Victor Bazarov, Aug 10, 2010
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan Keil

    Destruction order (e.g. singletons)

    Stephan Keil, Nov 16, 2004, in forum: C++
    Replies:
    0
    Views:
    460
    Stephan Keil
    Nov 16, 2004
  2. Replies:
    4
    Views:
    823
    Daniel T.
    Feb 16, 2006
  3. Davlet Panech
    Replies:
    4
    Views:
    359
    Davlet Panech
    Nov 10, 2006
  4. Dennis Jones
    Replies:
    2
    Views:
    340
    Dennis Jones
    Jan 5, 2007
  5. BeautifulMind
    Replies:
    7
    Views:
    667
    Ron Natalie
    Feb 8, 2007
Loading...

Share This Page