Title
Return type of container::erase(iterator) differs for associative containers
Status
cd1
Section
[associative.reqmts] [sequence.reqmts]
Submitter
Andrew Koenig

Created on 1999-03-02.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

[ Redmond: formally voted into WP. ]

Date: 2010-10-21.18:28:33

[ Sydney: the proposed wording went in the right direction, but it wasn't good enough. We want to return an iterator from the range form of erase as well as the single-iterator form. Also, the wording is slightly different from the wording we have for sequences; there's no good reason for having a difference. Matt provided new wording, (reflected above) which we will review at the next meeting. ]

Date: 2010-10-21.18:28:33

[ Post-Kona: the LWG agrees the return type should be iterator, not void. (Alex Stepanov agrees too.) Matt provided wording. ]

Date: 2010-10-21.18:28:33

[ Pre-Kona: reopened at the request of Howard Hinnant ]

Date: 2010-10-21.18:28:33

Proposed resolution:

In [associative.reqmts], in Table 69 Associative container requirements, change the return type of a.erase(q) from void to iterator. Change the assertion/not/pre/post-condition from "erases the element pointed to by q" to "erases the element pointed to by q. Returns an iterator pointing to the element immediately following q prior to the element being erased. If no such element exists, a.end() is returned."

In [associative.reqmts], in Table 69 Associative container requirements, change the return type of a.erase(q1, q2) from void to iterator. Change the assertion/not/pre/post-condition from "erases the elements in the range [q1, q2)" to "erases the elements in the range [q1, q2). Returns q2."

In [map], in the map class synopsis; and in [multimap], in the multimap class synopsis; and in [set], in the set class synopsis; and in [multiset], in the multiset class synopsis: change the signature of the first erase overload to

   iterator erase(iterator position);

and change the signature of the third erase overload to

  iterator erase(iterator first, iterator last); 
Date: 1999-03-02.00:00:00

Table 67 (23.1.1) says that container::erase(iterator) returns an iterator. Table 69 (23.1.2) says that in addition to this requirement, associative containers also say that container::erase(iterator) returns void. That's not an addition; it's a change to the requirements, which has the effect of making associative containers fail to meet the requirements for containers.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1502
2010-10-21 18:28:33adminsetmessages: + msg1501
2010-10-21 18:28:33adminsetmessages: + msg1500
2010-10-21 18:28:33adminsetmessages: + msg1499
2010-10-21 18:28:33adminsetmessages: + msg1498
1999-03-02 00:00:00admincreate