S
subramanian100in
Consider
vector<string> v;
If we call,
v.erase(v.end())
this invokes undefined behaviour.
But, if we call
v.erase(v.begin(), v.end())
or
v.erase(v.end(), v.end())
will these last two calls invoke undefined behaviour ? Why I am asking
is that v.clear() on an empty vector is valid - it does nothing.
v.clear() is equivalent to v.erase(v.begin(), v.end()) which in turn
is equal to v.erase(v.end(), v.end()) when 'v' is empty. Am I
correct ?
Kindly clarify.
Thanks
V.Subramanian
vector<string> v;
If we call,
v.erase(v.end())
this invokes undefined behaviour.
But, if we call
v.erase(v.begin(), v.end())
or
v.erase(v.end(), v.end())
will these last two calls invoke undefined behaviour ? Why I am asking
is that v.clear() on an empty vector is valid - it does nothing.
v.clear() is equivalent to v.erase(v.begin(), v.end()) which in turn
is equal to v.erase(v.end(), v.end()) when 'v' is empty. Am I
correct ?
Kindly clarify.
Thanks
V.Subramanian