From: ulrich.eckhardt@dominolaser.com   
      
   Am 16.05.2013 21:45, schrieb Andy Lutomirski:   
    > This has been annoying me for a while:   
   [...]   
    > template   
    > void IncrementVec(Vec &v)   
    > {   
    > for (size_t i = 0; i < v.size(); i++)   
    > ++v[i];   
    > }   
   [...]   
    > The code generation for f1 loads len_ on every iteration of the loop.   
      
   I'd say the default for-loop should look like this:   
      
    for(size_t i=0, size=v.size(); i!=size; ++i)   
      
   or for iterators:   
      
    for(iterator it=v.begin(), end=v.end(); it!=end; ++it)   
      
   This avoids any function call or load overhead on the loop variables.   
   Also note that using "!=" and prefix-increment should be automatic,   
   no-brain-involved actions of your typing hands anyway, since these are   
   guaranteed to work and perform.   
      
   That said, being able to annotate to the compiler/optimizer that some   
   things don't alias would be nice. I think that such subtle hints could   
   be used to improve quite some code where the compiler up to now has to   
   assume that some things could be modified by side effects.   
      
   Uli   
      
      
   --   
    [ 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)   
|