Is end() required to be constant in an STL map/set?

前端 未结 10 524
别跟我提以往
别跟我提以往 2021-02-01 15:00

§23.1.2.8 in the standard states that insertion/deletion operations on a set/map will not invalidate any iterators to those objects (except iterators pointing to a deleted eleme

10条回答
  •  逝去的感伤
    2021-02-01 15:13

    Iterators in (multi)sets and (multi)maps won't be invalidated in insertions and deletions and thus comparing .end() against previous stored values of .end() will always yield true.

    Take as an example GNU libstdc++ implementation where .end() in maps returns the default intialized value of Rb_tree_node

    From stl_tree.h:

      _M_initialize()
      {
        this->_M_header._M_color = _S_red;
        this->_M_header._M_parent = 0;
        this->_M_header._M_left = &this->_M_header;
        this->_M_header._M_right = &this->_M_header;
      }
    

提交回复
热议问题