Given two std :: iterators of the same type, how can I check if the same object (and not the class) comes from? Notice I am not asking how to compare their meanings.
std::string foo = "foo"; std::string bar = "bar"; std::string::iterator iter1 = foo.begin(); std::string::iterator iter2 = bar.begin(); if ( iter1 == iter2 ) { ... }
The above should and will not work. How can I check this at runtime? Looking in the source code, I see that the corresponding methods call iterator::_Compat() , this is the void method, which performs the check that I want, but if it fails, it displays a debug message. It will be imperceptible in releases.
In the future, I see that the iterator (at least for the string) has the public method _GetCont() . So
if ( iter1._GetCont() == iter2._GetCont() )
works. But this is undocumented, making me believe that it is unsafe.
My question is, how can I do the above in portable mode?
It should also be noted that this is part of the iterator pattern class. I will not control the second iterator.
source share