From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +UuXGt2PomoohzwAWB0awg (envelope-from ) for ; Thu, 10 Sep 2026 07:09:17 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Muld3WIw; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 68C261E09E; Thu, 10 Sep 2026 07:09:17 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9DF8C1E091 for ; Thu, 10 Sep 2026 07:09:16 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F8754B9DB4F for ; Thu, 10 Sep 2026 11:09:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F8754B9DB4F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Muld3WIw Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 7C8D74B9DB4F for ; Thu, 10 Sep 2026 11:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C8D74B9DB4F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 7C8D74B9DB4F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789038530; cv=none; b=MkjeIQCxZyr+GqIg8++b+wCMx1efvV0iHcWUPrD+PZ3knk0o86mEZ4+45uWMIhz6Kc4/fBcK3AyacgsJ/cnaRWhv13f5meroYDg7EanOXH5IfH4wsCvFdGqtR0NmhIs+8gxqelIdjglBqqVTsneIxWBraw4XCItHEhdsqBi17QE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789038530; c=relaxed/simple; bh=SY1jnG5u+T/9SuyRwcCxQD5u4OC/bPrc0Ahbs90HSrM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T3TYMwX6n++E7bkT6sdvlKLd8UeQ0CvCbO8xFBfaUBX+70elhynmgspsIdMZlixc223bZwP3DHsbJ+uAB4h8LecgMhPNYrxAfdyVx1JOd4TMTjxXvc9cljNyzr1HqgwGQa6Bhtdh52brPmDxoiqgi+QDGb6i+LBAY555VuUQ/zU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Muld3WIw DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C8D74B9DB4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789038529; 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: in-reply-to:in-reply-to:references:references; bh=wDAPzZ3LP6RdbTRUBUPGCWQBLQpEm7ntQmzP34MPFD8=; b=Muld3WIwqQXq9hhZ17TyW7uWT4QAQ5Dg6w2IUi62pr0XDVkaLN29MOjH94B95dK/EoWbjC eQZR2z/krXj+IB/FoE/9UXcIDCBgGayocROqb3nAee9GOSoB/x0+GDH4Fs7oubTH8YHnvq x54YinV4DXwDJzbhnOgjXn8vpoUoaqE= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-5k3ai5n6Pdy-OCHnXx2yXg-1; Thu, 10 Sep 2026 07:08:46 -0400 X-MC-Unique: 5k3ai5n6Pdy-OCHnXx2yXg-1 X-Mimecast-MFC-AGG-ID: 5k3ai5n6Pdy-OCHnXx2yXg_1789038525 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4957287363bso53111625e9.0 for ; Thu, 10 Sep 2026 04:08:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789038525; x=1789643325; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=wDAPzZ3LP6RdbTRUBUPGCWQBLQpEm7ntQmzP34MPFD8=; b=h6yOkbfH2zSTq+ih9tQQpgImBI85viIoN1+n5eBvai/U2mhPfZ2tNOrerpCFMHnXvd u1U8B7JfgPui7wiH0ERhzGJLQm/F64GMOLpEv+/jtO/jyxu+u4ph5QQO1QtEwaNe4Gq9 CUzs50nno9UlGsPi2fk5ZKT+285q3ADdShfL0iGeYv0FSGtcuVNPyck1dZDn21ZtY9kU bPjiuoxk0VJQOVtlY+vQNpxTJADRpCqFks4qnagDTM/ztNuYOwkGVU9AcNAAqGvro+er W9p/w5QdCvegIMDIUhji9u0BO0vWN67BC5FPvILOQ/ERm3fKfa3hFLdiGuBszGCsgS4b XV8g== X-Forwarded-Encrypted: i=1; AKwUvBzDc1GTNpLY4mk6xxm7PCw+TazVUeS0GKQYdHbdvrxEB25WFlx2Khyv6rrPeXKWl3Ln92kLcV35L4VGrg==@sourceware.org X-Gm-Message-State: AFuF++lPNjoP8P/zS82HD5k19hwOsT9Ca+obE0X/0OmJk0Hu+qcc5L2j flReqFAUsXAZtC9SiScbHuVlMB/WvQP7B1quk5/sshXBjcwJSEh1jMgRrsqws2o59QkLf91RYoJ 4dRYHu728IpqrSt5h5KQTniAOYJyGpLvAt4ffBYyVe+2A/wxIcAEgRawpa46mdX4= X-Gm-Gg: AYBFou1q9axxmjs6lYF2aztjye7jbpSo5F9v/JV+oixCg2IGQtWWcOaq0D1lLsxD5lD 4Yz2zBqt+wVMoDPOKgWRurTwIz3LuWpImfDxKCtevntyT/pRsTEb0B4GfLaeN9jmAFLG1yuKt8e wbt6y/251jbPauIBEPTeA3B8KsjyXXy67mKoUZDYnP9nvFmaaWqyjtuLKybsa04cAhBwNAtsgUz ID6fOUDOX9ITPrfY7EQIk83Gq+DEx+gShloZ43RjNiYjBzDXfc3/ObvN7hNevqviOuV2OWDpBwY GFbFtppoiHadHStAqB9lIvGUYuNZFVGdcfRNX7JLFzWhhNC1qoJVCfDmy202FDcr+6oK3Uz+m1W G/KdEEl2mJYMYAWCE X-Received: by 2002:a05:600c:3b07:b0:49c:fa20:cbfb with SMTP id 5b1f17b1804b1-49cfa20cd04mr385540485e9.18.1789038525476; Thu, 10 Sep 2026 04:08:45 -0700 (PDT) X-Received: by 2002:a05:600c:3b07:b0:49c:fa20:cbfb with SMTP id 5b1f17b1804b1-49cfa20cd04mr385539755e9.18.1789038524951; Thu, 10 Sep 2026 04:08:44 -0700 (PDT) Received: from localhost (59.6.93.209.dyn.plus.net. [209.93.6.59]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-485883a9b49sm42210756f8f.17.2026.09.10.04.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2026 04:08:44 -0700 (PDT) From: Andrew Burgess To: Matthieu Longo , gdb-patches@sourceware.org Cc: Simon Marchi , Thiago Jung Bauermann , Luis Machado , Luis Machado , Christina Joos , Kevin Buettner , Matthieu Longo Subject: Re: [PATCH v2 2/6] gdb support: add gdb::ranges::replace algorithm In-Reply-To: <87ik4de550.fsf@redhat.com> References: <20260825100912.514232-1-matthieu.longo@arm.com> <20260825100912.514232-3-matthieu.longo@arm.com> <87ik4de550.fsf@redhat.com> Date: Thu, 10 Sep 2026 12:08:43 +0100 Message-ID: <87fqzhe538.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ATkvnpUxjYVGeY4xKBlIcYSJwjBCgSIfy0puW8YuoLc_1789038525 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Andrew Burgess writes: > Matthieu Longo writes: > >> Provide a C++17-compatible replacement for the C++20 std::ranges::replace >> algorithm, allowing callers to use a consistent interface until GDB >> transitions to C++20. The helper should be removed once the C++ standard >> library implementation become available. >> >> https://en.cppreference.com/cpp/algorithm/ranges/replace >> --- >> gdbsupport/array-view.h | 16 ++++++++++++++++ >> 1 file changed, 16 insertions(+) >> >> diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h >> index 8431d7f5add..f9842ecff30 100644 >> --- a/gdbsupport/array-view.h >> +++ b/gdbsupport/array-view.h >> @@ -225,6 +225,22 @@ void copy (gdb::array_view src, gdb::array_view dest) >> std::copy_backward (src.begin (), src.end (), dest.end ()); >> } >> >> +namespace ranges { >> + >> +/* Replace all occurrences of a value in the provided range. >> + >> + Note: this helper is a reimplementation of std::ranges::replace, only >> + available from C++20 onwards, and consequently, should be replaced by >> + std::ranges::replace once GDB switches to C++20. */ >> + >> +template >> +void replace (Range r, const T &old_value, const T &new_value) > > Looking at the linked cppreference page, the C++20 functions take R as > 'Range &&r'. Doesn't your versions create a copy of the range? This > will work fine for non-owning ranges, like gdb::array_view, but will > mean replace operates on a copy of the range for something like > std::vector. Even if what you have above is intentional, I think this > difference should be highlighted and explained. > > Also, as this isn't specifically tied to gdb::array_view, I wonder if > this would be better put into a new file gdbsupport/ranges.h ? I don't > think anything much is needed to create the new file other than just > adding the file, so that should be pretty easy to do. Just as I hit send I realised that I should also say this would benefit from some unittests, see gdb/unittests/ for examples. Thanks, Andrew