How is STL iterator equality established?

后端 未结 4 2185
灰色年华
灰色年华 2021-02-13 19:33

I was wondering, how is equality (==) established for STL iterators? Is it a simple pointer comparison (and thus based on addresses) or something more fancy?

If I have t

4条回答
  •  不要未来只要你来
    2021-02-13 20:21

    Iterator classes can define overloaded == operators, if they want. So the result depends on the implementation of operator==.

    You're not really supposed to compare iterators from different containers. I think some debug STL implementations will signal a warning if you do this, which will help you catch cases of this erroneous usage in your code.

提交回复
热议问题