iterator vs reverse_iterator

前端 未结 6 1603
暗喜
暗喜 2021-01-05 05:52

I\'m using std::map to store a lot of elements (pairs of elements) and I have a \"little\" doubt. What is more efficient to iterate all elements over my

6条回答
  •  长发绾君心
    2021-01-05 06:24

    There will likely be no difference. std::reverse_iterator is just a template shim that translates ++'s to --'s at compile time.

    For a vector or other contiguous storage container, a forward iterator might interact very slightly better with the cache than a reverse iterator would (unlikely you'd be able to detect it), but for a tree-based container it won't make any difference at all--there won't be any locality of reference to exploit.

提交回复
热议问题