public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107850] [12 Regression] std::erase_if (map) forces predicate to takes a const value_type Date: Tue, 29 Nov 2022 11:06:02 +0000 [thread overview] Message-ID: <bug-107850-4-Nh0GuZeSZ4@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107850-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107850 --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Charles-Henri Gros from comment #4) > Looking into it further, there may be an implicit requirement that the > predicate does not modify its argument. > https://eel.is/c++draft/algorithms.requirements#6 See paragraph 4. That only applies to the Algorithms clause, not the Containers clause. So it doesn't apply to std::erase_if for maps. It *does* apply to std::erase_if for sequence containers, because those are defined in terms of std::remove_if, which is defined in the Algorithms clause. It doesn't apply to std::erase_if for sets, but *first is always const for those anyway so it's irrelevant. > I'm unfortunately not well-versed enough in C++ legalese to tell what > "possibly const" means in that context, A "glvalue u of type (possibly const) T" means u is a T& or const T&. Your predicate would fail that requirement (if it applied here) because it cannot be called with const T& at all, so pred(u) isn't a valid expression. > nor "apply any non-constant function". It means you can't modify the argument. > And while I understand that a "predicate" is generally meant to not do > modification, there are fairly frequent use cases for "apply this > potentially modifying operation, and depending on its result remove the > element from the container". You can write your own "modify and remove if" algo for that. > And in practice, this works (e.g. > std::remove_if, your own earlier version of erase_if, other compilers' > version...). It's undefined behaviour to do that with std::remove_if. > Maybe I should go to LEWG and lobby to remove that limitation. In the > meanwhile, I'll probably just keep my own, perhaps slightly less optimal > removal algorithms. There is no such restriction on std::erase_if for maps today, but I'll be lobbying the committee to *add* it!
next prev parent reply other threads:[~2022-11-29 11:06 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-23 21:34 [Bug c++/107850] New: " chgros at synopsys dot com 2022-11-23 22:08 ` [Bug libstdc++/107850] [12/13 Regression] " pinskia at gcc dot gnu.org 2022-11-24 8:18 ` redi at gcc dot gnu.org 2022-11-24 21:22 ` redi at gcc dot gnu.org 2022-11-25 15:07 ` cvs-commit at gcc dot gnu.org 2022-11-28 23:42 ` [Bug libstdc++/107850] [12 " chgros at synopsys dot com 2022-11-29 11:06 ` redi at gcc dot gnu.org [this message] 2022-11-29 11:20 ` redi at gcc dot gnu.org 2022-11-29 11:30 ` redi at gcc dot gnu.org 2022-11-29 16:22 ` chgros at synopsys dot com 2022-11-29 16:43 ` redi at gcc dot gnu.org 2022-11-29 18:48 ` chgros at synopsys dot com 2023-04-27 17:38 ` cvs-commit at gcc dot gnu.org 2023-04-27 17:38 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107850-4-Nh0GuZeSZ4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).