Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Matthieu Longo <matthieu.longo@arm.com>, gdb-patches@sourceware.org
Cc: Simon Marchi <simark@simark.ca>,
	Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	Luis Machado <luis.machado@amd.com>,
	Luis Machado <luis.machado.foss@gmail.com>,
	Christina Joos <christina.joos@intel.com>,
	Kevin Buettner <kevinb@redhat.com>,
	Matthieu Longo <matthieu.longo@arm.com>
Subject: Re: [PATCH v2 2/6] gdb support: add gdb::ranges::replace algorithm
Date: Thu, 10 Sep 2026 12:07:39 +0100	[thread overview]
Message-ID: <87ik4de550.fsf@redhat.com> (raw)
In-Reply-To: <20260825100912.514232-3-matthieu.longo@arm.com>

Matthieu Longo <matthieu.longo@arm.com> 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<U> src, gdb::array_view<T> 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 <class Range, typename T>
> +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.

Thanks,
Andrew


  reply	other threads:[~2026-09-10 11:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 10:09 [PATCH v2 0/6] gdb: introduce file_reader_t to read procfs files Matthieu Longo
2026-08-25 10:09 ` [PATCH v2 1/6] target_fileio_read_stralloc: add an optional length parameter Matthieu Longo
2026-09-10 10:55   ` Andrew Burgess
2026-08-25 10:09 ` [PATCH v2 2/6] gdb support: add gdb::ranges::replace algorithm Matthieu Longo
2026-09-10 11:07   ` Andrew Burgess [this message]
2026-09-10 11:08     ` Andrew Burgess
2026-08-25 10:09 ` [PATCH v2 3/6] gdb: introduce helper class file_reader_t Matthieu Longo
2026-09-10 15:35   ` Andrew Burgess
2026-08-25 10:09 ` [PATCH v2 4/6] gdb/linux-tdep: migrate linux_info_proc to file_reader_t Matthieu Longo
2026-09-10 16:31   ` Andrew Burgess
2026-08-25 10:09 ` [PATCH v2 5/6] gdb/linux-tdep: migrate linux_find_memory_regions_full " Matthieu Longo
2026-09-11  8:34   ` Andrew Burgess
2026-08-25 10:09 ` [PATCH v2 6/6] gdb/linux-tdep: remove legacy parse_smaps_data overload Matthieu Longo
2026-09-11  8:41   ` Andrew Burgess
2026-09-16 10:55     ` Matthieu Longo
2026-09-03 22:58 ` [PATCH v2 0/6] gdb: introduce file_reader_t to read procfs files Matthieu Longo
2026-09-08 10:27 ` Matthieu Longo

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=87ik4de550.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=christina.joos@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    --cc=luis.machado.foss@gmail.com \
    --cc=luis.machado@amd.com \
    --cc=matthieu.longo@arm.com \
    --cc=simark@simark.ca \
    --cc=thiago.bauermann@linaro.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: link
Be 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