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.)