This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++26 status.
std::erase for list should specify return type as
boolSection: 23.3.7.7 [forward.list.erasure], 23.3.11.6 [list.erasure] Status: C++26 Submitter: Hewill Kang Opened: 2024-08-07 Last modified: 2026-06-09
Priority: Not Prioritized
View all issues with C++26 status.
Discussion:
std::erase for list is specified to return
erase_if(c, [&](auto& elem) { return elem == value; }).
However, the template parameter Predicate of erase_if only requires that the
type of decltype(pred(...)) satisfies boolean-testable, i.e., the
return type of elem == value is not necessarily bool.
bool to avoid some
pedantic cases (demo):
#includestruct Bool { Bool(const Bool&) = delete; operator bool() const; }; struct Int { Bool& operator==(Int) const; }; int main() { std::list
l; std::erase(l, Int{}); // unnecessary hard error }
[2024-08-21; Reflector poll]
Set status to Tentatively Ready after nine votes in favour during reflector poll.
[Wrocław 2024-11-23; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4988.
Modify 23.3.7.7 [forward.list.erasure] as indicated:
templatetypename forward_list ::size_type erase(forward_list & c, const U& value); -1- Effects: Equivalent to:
return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
Modify 23.3.11.6 [list.erasure] as indicated:
templatetypename list ::size_type erase(list & c, const U& value); -1- Effects: Equivalent to:
return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });