Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q]: map::erase return type as it is in ISO

0 views
Skip to first unread message

andres...@my-dejanews.com

unread,
Mar 30, 1999, 3:00:00 AM3/30/99
to

Can anyone help with this: different specs said different about
map::erase(iterator) return type. In some cases it is void in others
it is an iterator. What is in ISO standard, void or iterator?

Andrei, and...@interworld.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own


[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]


James Kuyper

unread,
Mar 31, 1999, 3:00:00 AM3/31/99
to
andres...@my-dejanews.com wrote:
>
> Can anyone help with this: different specs said different about
> map::erase(iterator) return type. In some cases it is void in others
> it is an iterator. What is in ISO standard, void or iterator?

void.
---

Jerry Coffin

unread,
Mar 31, 1999, 3:00:00 AM3/31/99
to

In article <7dr01i$p0t$1...@nnrp1.dejanews.com>, andresmirnov@my-
dejanews.com says...

>
> Can anyone help with this: different specs said different about
> map::erase(iterator) return type. In some cases it is void in others
> it is an iterator. What is in ISO standard, void or iterator?

map::erase is really three overloaded functions. The two that take
iterators as arguments return void. The one that takes a key as an
argument returns a size_type.

Stan Brown

unread,
Apr 1, 1999, 3:00:00 AM4/1/99
to
[This followup was also e-mailed to the cited author.]

In this next-to-last year of the millennium, andres...@my-dejanews.com
(andres...@my-dejanews.com) wrote in comp.std.c++:


>
>Can anyone help with this: different specs said different about
>map::erase(iterator) return type. In some cases it is void in others
>it is an iterator. What is in ISO standard, void or iterator?

Page 491 of the standard gives three overloaded members 'erase' for
std:map:
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
A map is an associative container, and page 466 gives requirements for
associative containers. There are three 'erase's, which are the same as
the above but ordered 2,1,3.

According to the text on page 490, a map also meets the requirements of a
container and of a reversible container (subclause 23.1) and "most
operations described in (23.1.2) for unique keys. This means that a map
supports the a_uniq operations but not the a_eq operations."

There is an erase member function that returns an iterator, but it is for
sequence containers (vector, list, deque, page 462, subclause 23.1.1),
not maps.

If there's some reason why you can't buy the standard, you can access a
decent on-line reference to the library (not just STL) at P.J. Plauger's
company's site:
http://www.dinkumware.com/htm_cpl/
Unfortunately, the description at
http://www.dinkumware.com/htm_cpl/map.html#map::erase
does list an erase function returning an iterator (in place of the first
one I quoted above from the standard). That looks like an error to me,
but I could be wrong. I have sent a note to Dinkumware pointing out the
discrepancy and asking about this.

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.mindspring.com/~brahms/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
---

Stan Brown

unread,
Apr 1, 1999, 3:00:00 AM4/1/99
to

I wrote in comp.std.c++:

>Unfortunately, the description at
> http://www.dinkumware.com/htm_cpl/map.html#map::erase
>does list an erase function returning an iterator (in place of the first
>one I quoted above from the standard). That looks like an error to me,
>but I could be wrong. I have sent a note to Dinkumware pointing out the
>discrepancy and asking about this.

I got a reply from P.J. Plauger. Summary: the code matches the
documentation, but they don't conform to the standard. The return type
will remain "iterator" not "void" because it's useful.

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.mindspring.com/~brahms/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.

0 new messages