S
subramanian100in
Whenever we specify an iterator range to a container operation or an
std::algorithm, the first iterator should always be a valid iterator
ie it should point to some element in the respective container? Am I
correct?
For example, suppose
vector<string> v;
v.erase(v.begin(), v.end());
sort(v.begin(), v.end());
Here since 'v' is empty, v.begin() does not refer to an element in the
container. So
both the above statements invoke undefined behaviour. Am I correct ?
Kindly clarify.
Thanks
V.Subramanian
std::algorithm, the first iterator should always be a valid iterator
ie it should point to some element in the respective container? Am I
correct?
For example, suppose
vector<string> v;
v.erase(v.begin(), v.end());
sort(v.begin(), v.end());
Here since 'v' is empty, v.begin() does not refer to an element in the
container. So
both the above statements invoke undefined behaviour. Am I correct ?
Kindly clarify.
Thanks
V.Subramanian