Title
erase_if for flat_{,multi}set is incorrectly specified
Status
c++23
Section
[flat.set.erasure][flat.multiset.erasure]
Submitter
Tim Song

Created on 2023-02-09.00:00:00 last changed 5 months ago

Messages

Date: 2023-02-13.11:31:32

Proposed resolution:

This wording is relative to n4928.

  1. Modify [flat.set.erasure] as indicated:

    template<class Key, class Compare, class KeyContainer, class Predicate>
      typename flat_set<Key, Compare, KeyContainer>::size_type
        erase_if(flat_set<Key, Compare, KeyContainer>& c, Predicate pred);
    

    -1- Effects: Equivalent to:

    auto [erase_first, erase_last] = ranges::remove_if(c, pred);
    auto n = erase_last - erase_first;
    c.erase(erase_first, erase_last);
    return n;
    

    -1- Preconditions: Key meets the Cpp17MoveAssignable requirements.

    -2- Effects: Let E be bool(pred(as_const(e))). Erases all elements e in c for which E holds.

    -3- Returns: The number of elements erased.

    -4- Complexity: Exactly c.size() applications of the predicate.

    -5- Remarks: Stable ([algorithm.stable]). If an invocation of erase_if exits via an exception, c is in a valid but unspecified state ([defns.valid]).

    [Note 1: c still meets its invariants, but can be empty. — end note]

  2. Modify [flat.multiset.erasure] as indicated:

    template<class Key, class Compare, class KeyContainer, class Predicate>
      typename flat_multiset<Key, Compare, KeyContainer>::size_type
        erase_if(flat_multiset<Key, Compare, KeyContainer>& c, Predicate pred);
    

    -1- Effects: Equivalent to:

    auto [erase_first, erase_last] = ranges::remove_if(c, pred);
    auto n = erase_last - erase_first;
    c.erase(erase_first, erase_last);
    return n;
    

    -1- Preconditions: Key meets the Cpp17MoveAssignable requirements.

    -2- Effects: Let E be bool(pred(as_const(e))). Erases all elements e in c for which E holds.

    -3- Returns: The number of elements erased.

    -4- Complexity: Exactly c.size() applications of the predicate.

    -5- Remarks: Stable ([algorithm.stable]). If an invocation of erase_if exits via an exception, c is in a valid but unspecified state ([defns.valid]).

    [Note 1: c still meets its invariants, but can be empty. — end note]

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP. ]

Date: 2023-02-10.01:20:44

[ Issaquah 2023-02-09; LWG ]

Move to Immediate for C++23

Date: 2023-02-09.00:00:00

The current specification of erase_if for flat_{,multi}set calls ranges::remove_if on the set, which is obviously incorrect — the set only present constant views of its elements.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 11:31:32adminsetmessages: + msg13404
2023-02-13 11:31:32adminsetstatus: immediate -> wp
2023-02-10 01:20:44adminsetmessages: + msg13328
2023-02-10 01:20:44adminsetstatus: new -> immediate
2023-02-09 18:21:20adminsetmessages: + msg13316
2023-02-09 00:00:00admincreate