public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "chgros at synopsys dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107850] New: std::erase_if (map) forces predicate to takes a const value_type Date: Wed, 23 Nov 2022 21:34:58 +0000 [thread overview] Message-ID: <bug-107850-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107850 Bug ID: 107850 Summary: std::erase_if (map) forces predicate to takes a const value_type Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: chgros at synopsys dot com Target Milestone: --- g++11 will compile this program, but g++ 12.1.0 will not, because it complains that the predicate cannot take a const. The standard definition of erase_if (reproduced here for comparison purposes) indicates that g++11 is right in this case; this is a regression. #include <map> #include <string> using namespace std; template<typename Pred> int erase_if_by_std(map<string, string> &c, Pred pred) { auto original_size = c.size(); for (auto i = c.begin(), last = c.end(); i != last; ) { if (pred(*i)) { i = c.erase(i); } else { ++i; } } return original_size - c.size(); } int main(int argc, char const * const *argv) { auto pred = [&](pair<string const, string> &p) { if(p.first.size() == 2) { return true; } else { p.second.resize(3); return false; } }; map<string, string> m; erase_if_by_std(m, pred); std::erase_if(m, pred); }
next reply other threads:[~2022-11-23 21:34 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-11-23 21:34 chgros at synopsys dot com [this message] 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 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@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).