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,245 of 33,346    |
|    Dave Harris to Daniel James    |
|    Re: stl |
|    05 May 12 06:08:15    |
   
   From: brangdon@cix.compulink.co.uk   
      
   daniel@me.invalid (Daniel James) wrote (abridged):   
   > In article   
   > <9e1ed9de-2aa1-49fb-9dd4-c99d9d205a98@v2g2000vbv.googlegroups.com>,   
   > Edward Rosten wrote:   
   > > Note that there isn't a single instruction emitted between BEFORE   
   > > and AFTER, in other words, the call to erase is entirely erased.   
   >   
   > That, surely, is only possible here because the optimizer can tell   
   > that the vector i is not accessed after the call to erase, so   
   > optimizing away the clear will not change the observable behaviour   
   > of the program.   
      
   It's also possible because the compiler knows destroying an int is a   
   no-op. For example:   
      
    // (I use a wrapper because I'm not sure int::~int() is   
    // valid syntax).   
    struct Int { int i; };   
      
    void destroy( Int *p, size_t count ) {   
    for (size_t i = 0; i != count; ++i)   
    p[i].Int::~Int();   
    }   
      
   The loop has no observable effects and can be optimised away   
   completely. I don't know if GCC does this, but from comments in this   
   thread I'd be surprised if it didn't. The same principle allows   
   std::vector
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca