home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,348 of 33,346   
   James K. Lowden to Francis Glassborow   
   Re: std::vector: Surprising order of des   
   01 Jun 12 00:28:28   
   
   From: jklowden@speakeasy.net   
      
   On Thu, 31 May 2012 12:25:29 -0700 (PDT)   
   Francis Glassborow  wrote:   
      
   > As a general rule it is safe to destroy the elements in reverse order   
   > of construction.  However, note that if the programmer does use a swap   
   > () function or similar on elements of an array that reference each   
   > other then undefined behaviour is quite probable.   
      
   As a general rule, it is safe to destroy elements in any order at all.   
   We know that because that's what's been happening for decades.   
      
   No std container records the order of construction.  Efforts to infer   
   that order -- say, because vector elements were constructed   
   sequentially -- would fail in the general case.   
      
   swap() is only one example.  Assignment is another; any element in a   
   non-const collection can be overwritten by something else. That other   
   thing might have been constructed anytime, even before or after the   
   collection itself. In a collection of pointers, the pointed-to objects   
   could be assigned to.   
      
   --jkl   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca