Are const_iterators faster?

后端 未结 11 1866
挽巷
挽巷 2020-11-30 02:04

Our coding guidelines prefer const_iterator, because they are a little faster compared to a normal iterator. It seems like the compiler optimizes t

11条回答
  •  一向
    一向 (楼主)
    2020-11-30 02:23

    container::const_iterator::operator* returns a const T& instead of T&, so the compiler can make the usual optimizations for const objects.

提交回复
热议问题