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

前端 未结 10 515
别跟我提以往
别跟我提以往 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:22

    I believe that this depends entirely on what type of iterator is being used.

    In a vector, end() is the one past the end pointer and it will obviously change as elements are inserted and removed.

    In another kind of container, the end() iterator might be a special value like NULL or a default constructed element. In this case it doesn't change because it doesn't point at anything. Instead of being a pointer-like thing, end() is just a value to compare against.

    I believe that set and map iterators are the second kind, but I don't know of anything that requires them to be implemented in that way.

提交回复
热议问题