How to remove constness of const_iterator?

后端 未结 9 2488
囚心锁ツ
囚心锁ツ 2020-11-27 03:21

As an extension to this question Are const_iterators faster?, I have another question on const_iterators. How to remove constness of a const_iterator

9条回答
  •  醉梦人生
    2020-11-27 04:10

    Unfortunately linear time is the only way to do it:

    iter i(d.begin());
    advance (i,distance(i,ci));
    

    where iter and constIter are suitable typedefs and d is the container over which you are iterating.

提交回复
热议问题