C++ iterators & loop optimization -


I see a lot of C ++ code that looks like this:

  For (this const_iterator = List.begin (), const_iterator ite = list.end (); it! = Ite; ++ it)  

Unlike a more concise version:

 for  (const_iterator it = list.begin (); it! = List.end (); ++ it)  

between the two conventions in motion Will there be any difference? Natively will be slightly faster since the first list.end () is called once. But since the itater is a constraint, it seems that the compiler will pull this test out of the loop, creating the same assembly for both.

I will just mention for the record that the C ++ standard mandate that is Type and end () on any container type (this is the vector , list , map etc.). Only take time to hold In practice, these calls will almost certainly be included in a pointer comparison if you have to optimize Compile with.

Keep in mind that this guarantee is not necessary for additional vendor-supply "containers" which is not really


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -