C++ iterators & loop optimization

前端 未结 11 1173
渐次进展
渐次进展 2021-01-30 04:11

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

for( const_iterator it = list.begin(),
     const_iterator ite = list.end();
     it != ite; ++it)
<
11条回答
  •  攒了一身酷
    2021-01-30 04:51

    You can make the first version more concise and get the best of both:

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

    P.S. The iterators aren't const, they're iterators to a const reference. There's a big difference.

提交回复
热议问题