Skip to main content
GameDev.net gamedev.net
🔒 Locked

What does std::map ::erase return?

Started by rick_appleton Oct 20, 2008 at 6:08 AM 4 replies 2.6k views
Original Post
rick_appleton
rick_appleton
It could be void: http://www.sgi.com/tech/stl/Map.html or it could be std::map< >::iterator: http://www.dinkumware.com/manuals/default.aspx?manual=compleat&page=map.html#map::erase I thought the point of a standard was to make it possible to write code once and compile anywhere, but that doesn't work with this function, as the top one seems to be used by GCC, and the bottom version is used in Visual Studio.
dmatter
dmatter
Well according to 23.3.1 of the C++98/03 standards, the erase function is declared like this:

void erase(iterator position);
size_type erase(const key_type & x);
void erase(iterator first, iterator last);
scjohnno
scjohnno
From the Dinkumware site:

Quote:
In this implementation, the first two member functions return an iterator that designates the first element remaining beyond any elements removed, or end() if no such element exists.

Quote:
As much as possible, this Reference indicates any extensions to standard-conforming behavior particular to this implementation.


So the Dinkumware implementation is an extension upon the standard.
mrbastard
mrbastard
Quote:
Original post by rick_appleton
I thought the point of a standard was to make it possible to write code once and compile anywhere, but that doesn't work with this function, as the top one seems to be used by GCC, and the bottom version is used in Visual Studio.


So you can just use the top one?

[size="1"]
rick_appleton
rick_appleton
Hmm, that's interesting. Thank you for the replies. I will certainly use the top version to be consistent.

dmatter: Where did you find that in the standard? Somewhere online I hope?
dmatter
dmatter
Quote:
Original post by rick_appleton
dmatter: Where did you find that in the standard? Somewhere online I hope?
Well the standard itself isn't free, although fairly cheap. However a final draft is available online from a number of places and at no charge; it isn't significantly different from the finished version either, just re-wording and things of that nature.

For the map<>::erase function, I referred to section 23.3.1, titled "Class template map" (or "Template class map" depending on which version you read).

For completeness, the references to the two most recent standards are:
1998 standard: ISO/IEC 14882:1998(E)
2003 standard: ISO/IEC 14882:2003(E)

In either case erase returns void.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.