Caching the end iterator - Good idea or Bad Idea?

前端 未结 8 1736
臣服心动
臣服心动 2021-02-04 03:36

Generally speaking is it a good idea to cache an end iterator (specifically STL containers) for efficiency and speed purposes? such as in the following bit of code:



        
8条回答
  •  北海茫月
    2021-02-04 04:00

    In general it should not matter if you cache the end iterator. If you feel it does matter, then you should already be using a profiler on your code and would be able to profile both variations. I'd suspect it could differ depending upon the container type - but a profiler would be the only way to know for sure given your compiler, optimizations and STL vendor.

提交回复
热议问题