C++ Logo

STD-DISCUSSION

Advanced search

Subject: Sequential containers. Method erase with the iterator returned by end()
From: Vladimir Grigoriev (vlad.moscow_at_[hidden])
Date: 2020-04-29 09:52:31


I did not found in the standard where there is said what will occur if to use as the argument of the method erase the iterator returned by the method end.
 
For example this program ends abnormally.
 
#include <iostream>
#include <iostream>
#include <vector>
int main() 
{
    std::vector<int> v = { 1 };
    
    auto it = v.erase( v.end() );
    
    std::cout << std::boolalpha << ( it == v.end() ) << '\n';
 
    return 0;
}
 
While this program
 
#include <iostream>
#include <iostream>
#include <vector>
int main() 
{
    std::vector<int> v = { 1 };
    
    auto it = v.erase( v.end(), v.end() );
    
    std::cout << std::boolalpha << ( it == v.end() ) << '\n';
 
    return 0;
}
 
finishes normally.
 
For the class template std::string for the method
 
basic_string& erase(size_type pos = 0, size_type n = npos);
 
there is written clear that the argument that specifies the position can equal to the value of size().
 
But looking through sections describing sequential containers I did not find where something is said what happens when the passed iterator is the iterator returned by end().  
 
With best regards
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups