In Accelerated C++ section 6.1 pg 107 (for those who have it to hand) there is a function that returns true when passed a character that cannot be part of a URL.
The specific part I'm interested in is the following:
1 2 3 4 5 6 7
bool not_url_char(char c)
{
staticconst string url_ch = "~;/?:@=&$-_.+!*'(),";
return !(isalnum(c) ||
find(url_ch.begin(), url_ch.end(), c) != url_ch.end());
}
So, as I understand it, the function is passed a character, and on line 5 returns false if the character is an alphanumeric character, or any of the characters in the range (url_ch.begin(), url_ch.end()]
But after the call to find() on line 6, what is the use of != url_ch.end()? I don't understand why this is in the code and what its purpose is; I can't seem to relate it to anything in the function. It seems to be saying "do something if something != url_ch.end() but I don't know what either of the somethings are...I hope that makes sense.
It seems find returns the first iterator it finds to the given character, c.
I think the idea was that if the character isn't any of the characters in url_ch then it would end up returning the last iterator. != is the 'if not equals' operator, so returns true upon find not returning the end iterator, AKA returns true if any of the url_ch characters are found to be equal to c.
EDIT: And it returns in the range [url_ch.begin(), url_ch.end()]. It's possible for the first character to be the 'match' character.