From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7FDDF385AC19 for ; Thu, 7 Dec 2023 14:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FDDF385AC19 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7FDDF385AC19 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701957912; cv=none; b=Ez45OX7OTb6NGHSzgdeEPX7nlHgHNgEVbOzFIkal7xMwvzr7uT8j4SFcUhmWr7FUwXUyuqo7McFHqb39SNpGBUQflk+qKFg9a34klBGiwA6i1HknnriPaB/lxLqtluI3PksY3Y1I+6G7zzpHVuxlVeKgpC2T+cNuQLBVjXN8Bw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701957912; c=relaxed/simple; bh=bZCWnZSzfH5obxpZbQL4X2K7PzHHetFJZwikRaB3XR8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=eR5jEdXkvpSSZPrLeBpdfP+j25kQGK9YerhOQ+FKgZMET/UUCiVwJWLV1XwOOMNkBgaNXdkUlLdpcH5i9NoaOuOzlwYtjqTLM5Zt05Qr7qQpy2Jqs654/5OJgG2KKTEvWx1neAD3Y5p0ooOCYhmsetFr/u94bVBroOXwGrE6CUo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701957902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yzP1pbLsstze27jqAp9Ki+FIfZwTshNkrTYq9jatiZU=; b=PBSNry3Xl5lL3xVy6+eMqOVzMQrVH03aHDxw8rBAZw27s4nyCxGhZwbIvpQapylFnfXeJh QSAWf88OetGimQvviQ3wZG8IEyZMxQ3KAsFAYbZZVH8Cxa5cXkXik2ZJJFQbucpeabrVY0 2cbIBGUb8RVdra4tN+Z9hbYmE+y4JAo= Received: from mail-oa1-f72.google.com (mail-oa1-f72.google.com [209.85.160.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-Dn4L5WDnOtiE6El6L1j4wQ-1; Thu, 07 Dec 2023 09:05:00 -0500 X-MC-Unique: Dn4L5WDnOtiE6El6L1j4wQ-1 Received: by mail-oa1-f72.google.com with SMTP id 586e51a60fabf-1fb34e3da36so1581228fac.1 for ; Thu, 07 Dec 2023 06:04:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701957897; x=1702562697; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yzP1pbLsstze27jqAp9Ki+FIfZwTshNkrTYq9jatiZU=; b=Qba2cqz3XvilykJzdTAO40pQRCX0+emUIYSt4Uz+CsCjYEib44KDuEUUHt4KuZYwbU 5oN9DTbyeQigDZM0GFt98bot11E04ui1rT7SwXgEqS0QH0OGB1H0aD3MdssLycj3ySi7 qVZm5yd2rDPnNNmrrrombY2lkZvfjtEEnMjtt4T86JOK44ZjG99MvFTtQ/Ju/9HZmAHL PyRhFrghAF4EhEEU8/w/JGrk125PqJ0owXKa96eDZhtsOjJ9XRkwL2UK8ntPtL+Vayi9 CgaNvIE68cxf5a/YG2CMedNgYq1xNpqJ3Rprod7wc5vPyB49gPAqOYMoRyoUsWUJcvCO m/BQ== X-Gm-Message-State: AOJu0YwismRYZeqnpAgfWRDYkmdu7eY9sRlC24/4xPhYE0o9HUhX8jqA OBmyzbGWIQjlUgBHp8DXlYaaVywSyxt3OQlwOKJkG+25j1OS5ncPa0GoKdUjsXcQHbqLpaNyKDV 0GNKiqDOqqCPffqc/Yta3UQI/Z+g2CBU= X-Received: by 2002:a05:6871:799b:b0:1fa:ecfd:f596 with SMTP id pb27-20020a056871799b00b001faecfdf596mr2347799oac.14.1701957897189; Thu, 07 Dec 2023 06:04:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFM+rZTdn31lH9u+u/PErN4RuUsAPqtlg58sTmF8YsrHcUQ5O1oynaIleXCRJHB2c5LdsOzeTavCjkvMI21JM= X-Received: by 2002:a05:6871:799b:b0:1fa:ecfd:f596 with SMTP id pb27-20020a056871799b00b001faecfdf596mr2347786oac.14.1701957896936; Thu, 07 Dec 2023 06:04:56 -0800 (PST) MIME-Version: 1.0 References: <6b960f74-7ef7-8c3f-20bd-3f5a19d1f449@gmail.com> <9c9d0f26-4ca9-4c1b-86fa-63bc65d21ecf@gmail.com> In-Reply-To: From: Jonathan Wakely Date: Thu, 7 Dec 2023 14:04:45 +0000 Message-ID: Subject: Re: [PATCH] Reimplement __gnu_cxx::__ops operators To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 7 Dec 2023 at 13:41, Jonathan Wakely wrote: > > On Wed, 6 Dec 2023 at 20:55, Fran=C3=A7ois Dumont = wrote: > > > > I think I still got no feedback about this cleanup proposal. > > Can you remind me why we have all those different functions in > predefined_ops.h in the first place? I think it was to avoid having > two versions of every algorithm, one that does *l < *r and one that > does pred(*l, *r), right? > > One property of the current code is that _Iter_less_iter will compare > exactly *lhs < *rhs and so works even with this type, where its > operator< only accepts non-const arguments: > > struct X { bool operator<(X&); }; > > Doesn't your simplification break that, because the _Less function > only accepts const references now? > > Maybe another way to remove the number of types in predefined_ops.h > would be to compose functions from projections. So instead of > _Iter_less_iter and _Iter_less_val etc. we have: > > template > struct _Less > { > template > bool operator()(T& l, U& r) const > { return LProj()(l) < RProj()(r); } > }; > > And a set of projections: > > struct _Proj_deref { > template > decltype(auto) operator()(T& t) const > { return *t; } > }; > struct _Proj_identity { > template > T& operator()(T& t) const > { return t; } > }; > > Then: > > using _Iter_less_iter =3D_Less<_Proj_deref, _Proj_deref>; > using _Iter_less_val =3D _Less<_Proj_deref, _Proj_identity>; > > The problem here is the use of decltype(auto) which isn't valid in > C++98. If we didn't have to support C++98 then we could just use > forwarding refs in_Less::operator()(T&&, U&&) and use perfect > forwarding everywhere. But we can't. I suppose we could use typename iterator_traits::reference instead of decltype(auto), and hope that typedef is actuallyaccurate, and what dereferencing the iterator gives us. I do like the idea of simplifying the algos this way, I'm just concerned that the changes to the ops will break some code that works today. > > > > > > Here is a new version. > > > > Fran=C3=A7ois > > > > On 15/06/2023 07:07, Fran=C3=A7ois Dumont wrote: > > > I think we all agree that __gnu_cxx::__ops needed to be reimplemented= , > > > here it is. > > > > > > Note that I kept the usage of std::ref in , and . > > > > > > libstdc++: Reimplement __gnu_cxx::__ops operators > > > > > > Replace functors using iterators as input to adopt functors that > > > are matching the same Standard expectations as the ones imposed o= n > > > predicates used in predicates-aware algos. Doing so we need far l= ess > > > functors. It impose that iterators are dereference at algo level = and > > > not in the functors anymore. > > > > > > libstdc++-v3/ChangeLog: > > > > > > * include/std/functional (_Not_fn): Move to... > > > * include/bits/predefined_ops.h: ...here, and expose a > > > version > > > in pre-C++14 mode. > > > (__not_fn): New, use latter. > > > (_Iter_less_iter, _Iter_less_val, _Val_less_iter, > > > _Iter_equal_to_iter) > > > (_Iter_equal_to_val, _Iter_comp_iter, _Iter_comp_val, > > > _Val_comp_iter) > > > (_Iter_equals_val, _Iter_equals_iter, _Iter_pred, > > > _Iter_comp_val) > > > (_Iter_comp_to_val, _Iter_comp_to_iter, _Iter_negate): > > > Remove. > > > (__iter_less_iter, __iter_less_val, __iter_comp_val, > > > __val_less_iter) > > > (__val_comp_iter, __iter_equal_to_iter, > > > __iter_equal_to_val, __iter_comp_iter) > > > (__val_comp_iter, __iter_equals_val, __iter_comp_iter, > > > __pred_iter): Remove. > > > (_Less, _Equal_to, _Equal_to_val, _Comp_val): New. > > > (__less, __equal_to, __comp_val): New. > > > * include/bits/stl_algo.h: Adapt all algos to use new > > > __gnu_cxx::__ops operators. > > > When possible use std::move to pass predicates between > > > routines. > > > * include/bits/stl_algobase.h: Likewise. > > > * include/bits/stl_heap.h: Likewise. > > > * include/std/deque: Cleanup usage of __gnu_cxx::__ops > > > operators. > > > * include/std/string: Likewise. > > > * include/std/vector: Likewise. > > > > > > Tested under Linux x86_64 normal and _GLIBCXX_DEBUG modes. > > > > > > Ok to commit ? > > > > > > Fran=C3=A7ois > > >