While iterating through a std::map or std::vector or any container which has iterator in it, is checked against the variable.end() and not something like container<>::end. For example,
map<int, int> var;
for(map<int, int>::iterator it = var.begin(); it != var.end(); it++)
...                                           ^^^^^^^^^^^^^^^
Can't above highlighted part be something like:
it != map<int,int>::end
which is similar to static member string::npos. What can be the reason behind the design decision for providing .end() on per variable bases and not on the per type of container bases ? (i.e. map<int,int>::end and map<int,double>::end would be different; but for every map<int,int> variable, the ::end will be similar.)
This way, some array-based containers could implement an iterator simply as a pointer to an element. The one-past-the-last-element pointer is different for every array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With