title: Test if two iterators come from same object
body: <p>Given two std::iterators of the same type, how is it possible to test if the come from the same object (not class)? Note, I'm not asking how to compare their values.</p>
  
  <pre><code>std::string foo = "foo";
  std::string bar = "bar";
  
  std::string::iterator iter1 = foo.begin();
  std::string::iterator iter2 = bar.begin();
  
  if ( iter1 == iter2 )
  {
      ...
  }
  </code></pre>
  
  <p>The above should and does fail. How can I check for this at runtime? Looking into the source code, I see that the relevant methods call on <code>iterator::_Compat()</code> this is a void method that does the check I want but on failure it issues a debug assertation. It will go unnoticed in release builds.</p>
  
  <p>Looking further I see that the iterator (for string at least) has a public <code>_GetCont()</code> method. So</p>
  
  <pre><code>if ( iter1._GetCont() == iter2._GetCont() )
  </code></pre>
  
  <p>works. But, this is undocumented leading me to believe it's not safe to use.</p>
  
  <p>My question is how can I accomplish the above in a portable manner?</p>
  
  <p>Also to note, this is part of an iterator template class. I will have no control over the second iterator.</p>