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 81C2E3858297 for ; Thu, 7 Dec 2023 13:42:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81C2E3858297 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 81C2E3858297 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=1701956536; cv=none; b=DPSkJzPR6TjCPnGGmNWCo2WdIxXSmgw9c8JOheHBk3ckNEJ+uB7teogi98ub9xd0wTH5aiDq2jaSFadoceX5WnJiSKiaAAPp+0cQ1cZ3pzuD6tSUPg86X361l9c/+mCWqupcYW50IdDF6t/7kb8OL+zOW/KHRA5sKKpsCqvendc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701956536; c=relaxed/simple; bh=rSKXdw3eX317fZLL8KikR3VITHJYQcnmW2E/VR1qdN8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=F8RqiXBKQqIpgU4eB4a/1Rx4+4EdK2ptG0Xbtf+A2sWjrxcCNvgsNMFl6fFiHQWHoYhlEj2wqAZO+Oae1xPWXGxgwUgZctr3IpmWVhAhu0TifBSKPerOyJMoud+DC48fzx7UsKWM6zZp4XPjvNbHnfwFF0WuP+z4gVFOePybdS0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701956532; 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=CZ0c110xPTLzSgTzxg6z67Hx8aLxhfiT0T6I0Fdl3ik=; b=ZxG6dA52DJDZ6MUmSiuYRVsZ1e84q1hj/iKiQcl2OM9Bk+8ib6B00vCz8UlFLbR657nINg fHUzY7iBNlTPDZiZFOZLmqXG+uwA6YzhlM2DJUWg3505VM8OzIjLj30opJht6c5H5azIG0 ZrGXY7e2t1mVnuSrUVU6X+TCC84kiNI= Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-170-h1aJumdQMg2FmUBANsD5kA-1; Thu, 07 Dec 2023 08:42:10 -0500 X-MC-Unique: h1aJumdQMg2FmUBANsD5kA-1 Received: by mail-yb1-f200.google.com with SMTP id 3f1490d57ef6-db54c11887aso1182830276.1 for ; Thu, 07 Dec 2023 05:42:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701956530; x=1702561330; 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=CZ0c110xPTLzSgTzxg6z67Hx8aLxhfiT0T6I0Fdl3ik=; b=e6oYQVAwbm41mosolRX7Hr+vBicxS7hDfGuPVyR1SRz2lGEf26rTPQxijq/V99oxOl hu71vi3/2cxk5g/DG21V6y4A/MJsIMosJviEb5wO8Lfypj4J2tlVxCzvAMOPgBjh21Wn LeaT1itQjwIMa0GyXD/UiAtCNJRvbIQUWCFT8EVkyP58hILlzfCyc5E4O0p7kTOxIKLr bDIibK2oHifs1GF3cRGxrQ/Uv2YkBryiCSYXm6YJp7aLZBohrQMolHKsaUyJPmCLtCiX 0xCzFhhMaoLr29KJFShUjQ/7QGe9Dx5J7FnbvKpM78mD8P4ztIYyt9C3jl1BnNIadhp/ v8Gw== X-Gm-Message-State: AOJu0YzTrioj809qRTPmm6AD3pSSu33GWcXf5mZU1odhoX3RG82mTA95 9oG64gmmQDglaTb+hVIy45D7++INYVZ8EnGzvqDHCTopA8dFQ14nnYijKOn46OSqaDvcNSRaU1k 5zE04ojbiS1NzYGffFIGXdB5PZkJPc70= X-Received: by 2002:a25:838d:0:b0:db7:dad0:60c3 with SMTP id t13-20020a25838d000000b00db7dad060c3mr2247615ybk.80.1701956530194; Thu, 07 Dec 2023 05:42:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IEckgfPYp9mXa25J2nwNBzvEWop1I/U8dT9SoD+V4d3jTuRQIeYBQcaYDK9Kzm3/8K7l49NYFjRw6mHFNROcAk= X-Received: by 2002:a25:838d:0:b0:db7:dad0:60c3 with SMTP id t13-20020a25838d000000b00db7dad060c3mr2247607ybk.80.1701956529903; Thu, 07 Dec 2023 05:42:09 -0800 (PST) MIME-Version: 1.0 References: <6b960f74-7ef7-8c3f-20bd-3f5a19d1f449@gmail.com> <9c9d0f26-4ca9-4c1b-86fa-63bc65d21ecf@gmail.com> In-Reply-To: <9c9d0f26-4ca9-4c1b-86fa-63bc65d21ecf@gmail.com> From: Jonathan Wakely Date: Thu, 7 Dec 2023 13:41:58 +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=-6.2 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,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Wed, 6 Dec 2023 at 20:55, Fran=C3=A7ois Dumont wr= ote: > > 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. > > 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 on > > predicates used in predicates-aware algos. Doing so we need far les= s > > functors. It impose that iterators are dereference at algo level an= d > > 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 > >