Past-the-end iterator invalidation in C++11

后端 未结 3 1337
说谎
说谎 2020-12-29 04:05

The most popular post on C++ Iterator invalidation rules claims that it\'s not clear if the past-the-end iterators (i.e., those returned by end(), cend()<

3条回答
  •  一生所求
    2020-12-29 04:58

    At least in GCC end iterator gets invalidated for std::map:

    #include 
    #include 
    #include 
    int main() {
      std::set a;
      a.insert(1);
      std::set::reverse_iterator rit(a.rbegin());
      ++rit;
      assert(rit==a.rend());
      a.erase(a.begin());
      assert(a.rend()==rit); // FAIL
    }
    

提交回复
热议问题