Why does std :: set <K, C, A> :: erase accept a const_iterator?

It seems that in accordance with ISO 14882 2003 (aka St. Standard C ++) std::set<K, C, A>::erasetakes iterator(and not const_iterator) as a parameter

out of 23.3.3 [2]

void erase(iterator position);

It may also be noteworthy that when implementing the STL that comes with VS2008, erasing takes const_iterator, which led to an unpleasant surprise when I tried to compile my code with another compiler. Now, since my version accepts const_iterator, then you can implement erasure using const_iterator(as if it were not self-evident).

I believe that the standardization committee had some implementation (or an existing implementation at hand) that would require erasure for adoption iterator.

  • If you agree that this is so, you can describe an implementation set::erasethat will require changing the element to be deleted (I cannot).
  • If you do not agree, tell me why on Earth they will come up with this solution? I want to say that erasing an element is just a rearrangement of pointers!

EDIT

It just occurred to me that even in the case of an iterator, you cannot change an element in a set. But the question still remains - why not a const_iterator, especially if they are equivalent in some ways

+5
source share
3 answers

. ++ 11, set<K,C,A>::erase const_iterator:

iterator erase(const_iterator position);

2007 , . , , , , .

+4

- , iterator, : op, , iterator, , iterator :

  • erase .
  • insert(iter, val) .
  • .
0
-1
source

All Articles