Erase map item via a const_iterator

  • Thread starter Alf P. Steinbach
  • Start date
A

Alf P. Steinbach

Given a map<K,V>::const_iterator, how to erase the referred to element in
constant time?

I think the apparent lack of a way to do it is a basic design error with map and
possibly other containers, that they've misunderstood logical constness.

The issue popped up some time ago when I was answering a question in
[alt.comp.lang.learn.c-c++],


Cheers & TIA.,

- Alf (if you delete an 'e', and type an 'e' again, is it the same 'e', eh?)
 
N

none

Alf said:
- Alf (if you delete an 'e', and type an 'e' again, is it the same
'e', eh?)

No joke, I have had that exact same thought. It is probably a sign that I
am completely insane, but I have even followed the train of thought
further...

If I select/cut/paste an 'e', is it the same 'e'?

If I delete an 'e' and then "undo" the deletion, is it more the same 'e'
than it would have been if I had typed a new 'e'?

I understand every step that happens from the instant when the metal
contacts under my 'e' key touch each other to the dispatch of the
WM_KEYDOWN message to the application. Yet, somehow, I can't convince
myself that when you delete that 'e' and type a new one, it is the same
'e'.

Related question: If I gave you a rock composed of 10^20 atoms, along with
a list of every atom's exact <x,y,z> position in space, then destroyed that
rock completely, and then reassembled it to so that every atom's new
<x,y,z> was the same as it was originally, would it be the same rock?
 
J

James Kanze

Given a map<K,V>::const_iterator, how to erase the referred to element in
constant time?
I think the apparent lack of a way to do it is a basic design
error with map and possibly other containers, that they've
misunderstood logical constness.

You're not alone in thinking this. It will be corrected in the
next version (where map<>::erase takes const_iterator's).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top