Alex Rivera | Logout

How is STL iterator equality established?

Asked 2009-05-10T05:32:49.460
12

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 two iterators from two different list objects and I compare them, will the result always be false?

What about if I compare a valid value with one that's out of range? Is that always false?

Edit
Report

1 Answer

13

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.

answered 2009-05-10T05:38:43.580

Your Answer