Reputation: 786
Given just a std::string iterator, is it possible to determine the start and end points of the string? Supposing that I don't have access to the string object and so cannot call string.begin() and string.end(), and all I can do is increment or decrement the iterator and test the value.
Thanks, Phil
Upvotes: 10
Views: 2544
Reputation: 533
The default std::string::iterator is just a random, bi-direction iterator, doesn't know anything about container.
But if you're working on Visual C++ platform, maybe you can use some hacking way like following to get the control to its container, but it's very dangerous:
// it is the passed in string::iterator parameter.
if (it._Has_container()) {
string* strRef = (string*)it._Mycont;
}
Upvotes: 1
Reputation:
The short answer is no. The long answer is, because iterators aren't expected to know about the containers or ranges that are iterating over, they are only expected to
Furthermore certain types iterators may do more than just the above, but principally they are all required to have/perform the above in some form or another.
Upvotes: 6