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,387 of 33,346   
   Seungbeom Kim to All   
   Re: std::vector: Surprising order of des   
   07 Jun 12 21:24:43   
   
   From: musiphil@bawi.org   
      
   On 2012-06-07 11:57, Nevin ":-]" Liber wrote:   
   > In article ,   
   >  Seungbeom Kim  wrote:   
   >>   
   >> A user sensible enough could start something with an array, and   
   >> then later decide to switch to a vector. If a complex program   
   >> crashes just after switching from an array to a vector, the user   
   >> will have to spend a good amount of time debugging it in   
   >> frustration.   
   >   
   > Being dependent on order of destruction within a container is rare.   
      
   That is probably so, though others may disagree.   
      
   Then, as I paid attention to what may happen when switching from   
   arrays to vectors, I wonder why arrays have a specified order of   
   destruction in the first place, and why even temporaries do.   
      
   On the other hand, I also wonder if implementations really need the   
   freedom of the destruction order.   
      
   > If you really need it, you can always make your own destructor   
   > enforce it.   
      
   You mean, by writing your own container class with the destructor   
   enforcing the destruction order of its elements? You certainly can,   
   but it's off the topic here.   
      
   > If we tighten the requirements on the destructor, what should the   
   > following do:   
   >   
   > v.clear()   
   > v.erase(v.begin(), v.end())   
   >   
   > Should other sequence containers also be changed?  Arguably, people   
   > use deques and lists for FIFOs, so they could use the guarantee too.   
   > (On the other hand, you can still make a FIFO with push_front and   
   > pop_back.)   
      
   I think it would have been nice with a reverse order of destruction   
   specified for these as well, unless there had not been a reason   
   otherwise.  It's natural and not less efficient than the forward   
   order; you feel much more comfortable popping from the back than from   
   the front, don't we? ;-)   
      
   The violation of the principle of least surprise is much less   
   significant here, though, because arrays don't have such member   
   functions.   
      
   --   
   Seungbeom Kim   
      
      
         [ 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