Is Iterator initialization inside for loop considered bad style, and why?

前端 未结 13 1438
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 19:37

Typically you will find STL code like this:

for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter != m_SomeMemberContainerVar.end         


        
相关标签:
13条回答
  • 2021-02-05 20:21

    Having looked at this in g++ at -O2 optimisation (just to be specific)

    There is no difference in the generated code for std::vector, std::list and std::map (and friends). There is a tiny overhead with std::deque.

    So in general, from a performance viewpoint it makes little difference.

    0 讨论(0)
提交回复
热议问题