You can't. There's no method to check that. You must structure your code so that your iterator is between list.begin() and list.end().
Use iterator this way:
for (std::list<int>::const_iterator it = myList.begin(); it != myList.end(); ++it)
cout << *it << " ";
You can't compare [EDIT] list iterators with relational operators (<, >, <=, >=), so when you use an iterator outside a for loop, then you must always check if you go outside the bounds by comparing to begin() (if your going backward with --it) or with end() (if your going forward with ++it).
std::list<int>::const_iterator it = ... // initialized with some CORRECT value
// going backward
while (true)
{
cout << *it;
if (it == list.begin())
break;
--it;
}
// going forward
while (true)
{
cout << *it;
++it;
if (it == list.end())
break;
}
// or simplier
while (it != list.end())
{
cout << *it;
++it;
}
If, for some reason, you really need a check, then you can loop through the list and check if any of the iterators is equal to yours. But this may have a considerable impact on performance, so use it only in debug or/and in tests.