1041. Add associative/unordered container functions that allow to extract elements

Section: 23.2.7 [associative.reqmts] Status: Resolved Submitter: Alisdair Meredith Opened: 2009-03-12 Last modified: 2020-09-06

Priority: Not Prioritized

View other active issues in [associative.reqmts].

View all other issues in [associative.reqmts].

View all issues with Resolved status.

Discussion:

Addresses UK 239 [CD1]

It is not possible to take a move-only key out of an unordered container, such as (multi)set or (multi)map, or the new unordered containers.

Add below a.erase(q), a.extract(q), with the following notation:

a.extract(q)>, Return type pair<key, iterator> Extracts the element pointed to by q and erases it from the set. Returns a pair containing the value pointed to by q and an iterator pointing to the element immediately following q prior to the element being erased. If no such element exists,returns a.end().

[ Summit: ]

We look forward to a paper on this topic. We recommend no action until a paper is available. The paper would need to address exception safety.

[ Post Summit Alisdair adds: ]

Would value_type be a better return type than key_type?

[ 2009-07 post-Frankfurt: ]

Leave Open. Alisdair to contact Chris Jefferson about this.

[ 2009-09-20 Howard adds: ]

See the 2009-09-19 comment of 839 for an API which accomplishes this functionality and also addresses several other use cases which this proposal does not.

[ 2009-10 Santa Cruz: ]

Mark as NAD Future. No consensus to make the change at this time.

Original resolution [SUPERSEDED]:

In 23.2.7 [associative.reqmts] Table 85, add:

Table 85 -- Associative container requirements (in addition to container)
Expression Return type Assertion/note
pre-/post-condition
Complexity
a.erase(q) ... ... ...
a.extract(q) pair<key_type, iterator> Extracts the element pointed to by q and erases it from the set. Returns a pair containing the value pointed to by q and an iterator pointing to the element immediately following q prior to the element being erased. If no such element exists, returns a.end(). amortized constant

In 23.2.8 [unord.req] Table 87, add:

Table 87 -- Unordered associative container requirements (in addition to container)
Expression Return type Assertion/note
pre-/post-condition
Complexity
a.erase(q) ... ... ...
a.extract(q) pair<key_type, iterator> Extracts the element pointed to by q and erases it from the set. Returns a pair containing the value pointed to by q and an iterator pointing to the element immediately following q prior to the element being erased. If no such element exists, returns a.end(). amortized constant

[08-2016, Post-Chicago]

Move to Tentatively Resolved

Proposed resolution:

This functionality is provided by P0083R3