From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 36A8538532ED; Mon, 28 Nov 2022 23:42:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36A8538532ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669678959; bh=wUXL3ueb4RDdY66yXXt/NvSq5M1l2znc0mxYvtzrBF0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sFCChliYQKvwDekWY4sJDFwgsBfhW3Q7e1qMPjhUXN1iMoOjiHoac3H2al/y6TtVE LYSuO6L7HaKfdp0EAf5qox8jVT30tq6uGv+xl58rQSipDgrpsYNgdxRUJOp/Q7NIUi MewNbgsst/EMmfvAxQvtvC3WUBazxeE/LLIF6/sE= From: "chgros at synopsys dot com" 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: Mon, 28 Nov 2022 23:42:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: chgros at synopsys dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107850 --- Comment #4 from Charles-Henri Gros --- 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 "When not otherwise constrained, the Predicate parameter is used whenever an algorithm expects a function object ([function.objects]) that, when applied= to the result of dereferencing the corresponding iterator, returns a value testable as true. In other words, if an algorithm takes Predicate pred as its argument and fi= rst as its iterator argument with value type T, it should work correctly in the construct pred(*first) contextually converted to bool ([conv]). The function object pred shall not apply any non-constant function through = the dereferenced iterator. Given a glvalue u of type (possibly const) T that designates the same objec= t as *first, pred(u) shall be a valid expression that is equal to pred(*first)." I'm unfortunately not well-versed enough in C++ legalese to tell what "poss= ibly const" means in that context, nor "apply any non-constant function". And while I understand that a "predicate" is generally meant to not do modification, there are fairly frequent use cases for "apply this potential= ly modifying operation, and depending on its result remove the element from the container". And in practice, this works (e.g. std::remove_if, your own earl= ier version of erase_if, other compilers' version...). 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.=