0

I've been comparing documentation for the multimap::erase function. After checking out Josuttis and cplusplus.com, it looks as though there are three overloads:

void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);

However, the MSDN documentaion appears to suggest three slightly different overloads:

iterator erase(iterator where);
iterator erase(iterator first, iterator last);
bool erase(key_type key)

Why the differences? Am I just being a bit slow and looking at the wrong docs, or has the standard moved on and I'm just looking at outdated documentation?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
WalderFrey
  • 575
  • 2
  • 17
  • 2
    [cplusplus.com? Don't.](http://jcatki.no-ip.org/fncpp/cplusplus.com) – Griwes Jul 03 '12 at 12:01
  • 1
    @Griwes: This website indeed has some defects at time, but it is worth noting that they actually [fix their mistakes as long as you tell them](http://stackoverflow.com/questions/3316853/am-i-misunderstanding-assert-usage). – ereOn Jul 03 '12 at 12:11
  • @ereOn, it doesn't change a bit - until they fix **all** the problems, not some randomly chosen bits - especially those problems with coding style tomalak mentioned in that answer on Programmers.SE, it shouldn't be used. – Griwes Jul 03 '12 at 12:15
  • @Griwes: My point exactly. Complaining about the site is one thing (and is justified), but complaining without informing the authors about their mistakes is pointless. If everybody was acting that way, SO wouldn't work either. – ereOn Jul 03 '12 at 12:19
  • 1
    @ereOn, in one of answers in that deleted question **there were people who said they tried to contact with authors of that site**. With no response. Go on, send them the link I provided in first comment and see if you get any response. – Griwes Jul 03 '12 at 12:24
  • @Griwes: Well, my question proves this is not always true. You seem rather partial regarding this site so I won't argue with you any longer. I agree the site could be better, but my point is that discouraging people to behave well and inform the authors about their mistakes is bad. Had you fell from a bike as a child, would you recommend to everybody not to buy bikes ever ? – ereOn Jul 03 '12 at 12:30
  • 1
    @ereOn, the problem is that attempts to suggest them to fix the site were mostly ignored. As simple as that. – Griwes Jul 03 '12 at 12:39

4 Answers4

2

The correct overloads are (from http://en.cppreference.com/w/cpp/container/multimap/erase):

void erase( iterator position );                                    (until C++11) 
iterator erase( const_iterator position );                          (since C++11)

void erase( iterator first, iterator last );                        (until C++11) 
iterator erase( const_iterator first, const_iterator last );        (since C++11)

size_type erase( const key_type& key );

The cplusplus.com documentation is out of date; the Microsoft documentation is simply incorrect (overloads possibly copied erroneously from map documentation); it does say later that the third form returns a count of the number of elements removed so clearly cannot return bool.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • Okay, so the standard has moved on. Looked all over for something to tell me that and came up short. Guess I should've looked harder ;-) Thanks. – WalderFrey Jul 03 '12 at 12:20
2

According to this, it actually depends on the version of the standard your STL is conforming to. What you read on MSDN is C++ 11, and on cplusplus.com it's for older C++.

Antoine
  • 13,494
  • 6
  • 40
  • 52
2

The link from MSDN appears to document a library that wraps the STL for use in CLR. The first code snippet is correct and is the same as that in C++03 standard, and only differs from the C++11 standard in the iterators are const. From section 23.4.5.1 Class template multimap overview of the C++11 standard:

iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);
hmjd
  • 120,187
  • 20
  • 207
  • 252
1

The MSDN documentation you linked to is the STL/CLR version. That's a subset of the Standard C++ Library for use with C++ and the .NET Framework common language runtime (CLR).

The correct MSDN C++ documentation for std::multimap::erase is here.

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70