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


Author: brahms@mindspring.com (Stan Brown)
Date: 1999/04/01
Raw View
[This followup was also e-mailed to the cited author.]

In this next-to-last year of the millennium, andresmirnov@my-dejanews.com
(andresmirnov@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.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: brahms@mindspring.com (Stan Brown)
Date: 1999/04/01
Raw View
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.


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






Author: andresmirnov@my-dejanews.com
Date: 1999/03/30
Raw View
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, andreis@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-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/31
Raw View
andresmirnov@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.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/03/31
Raw View
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.


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