Performance of pIter != cont.end() in for loop

后端 未结 7 443
面向向阳花
面向向阳花 2021-01-07 18:11

I was getting through \"Exceptional C++\" by Herb Sutter lately, and I have serious doubts about a particular recommendation he gives in Item 6 - Temporary Objects.

7条回答
  •  不思量自难忘°
    2021-01-07 18:33

    Containers like vector returns variable, which stores pointer to the end, on end() call, that optimized. If you've written container which does some lookups, etc on end() call consider writing

    for (list::const_iterator i = emps.begin(), end = emps.end(); i != end; ++i)
    {
    ...
    }
    

    for speed

提交回复
热议问题