From: Matthieu Longo <matthieu.longo@arm.com>
To: Kevin Buettner <kevinb@redhat.com>
Cc: gdb-patches@sourceware.org, Luis Machado <luis.machado@amd.com>,
Luis Machado <luis.machado.foss@gmail.com>,
Andrew Burgess <aburgess@redhat.com>,
Yury Khrustalev <yury.khrustalev@arm.com>,
Pedro Alves <pedro@palves.net>, Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH v1 04/10] gdb support: add gdb::replace algorithm for iterators and ranges
Date: Mon, 13 Jul 2026 16:51:47 +0100 [thread overview]
Message-ID: <77b1efaf-3a30-4663-87f3-ea3814c54474@arm.com> (raw)
In-Reply-To: <20260710142150.64b2a9aa@f44-mesa-1>
On 10/07/2026 22:21, Kevin Buettner wrote:
> Hi Matthieu,
>
> I am not a C++ expert, but I'd like to understand this better...
>
> On Tue, 7 Jul 2026 16:48:54 +0100
> Matthieu Longo <matthieu.longo@arm.com> wrote:
>
>> Add a gdb::replace helper that mirrors the behavior of std::replace
>> for iterator pairs, together with a convenience overload accepting a
>> range.
>>
>> This provides a C++17-compatible replacement for the C++20 std::replace/
>> std::ranges::replace algorithms, allowing callers to use a consistent
>> interface until GDB transitions to C++20. The helpers should be removed
>> once the C++ standard library implementations become available.
>> ---
>> gdbsupport/array-view.h | 26 ++++++++++++++++++++++++++
>> 1 file changed, 26 insertions(+)
>>
>> diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h
>> index 8431d7f5add..61119d7a8e2 100644
>> --- a/gdbsupport/array-view.h
>> +++ b/gdbsupport/array-view.h
>> @@ -225,6 +225,32 @@ void copy (gdb::array_view<U> src, gdb::array_view<T> dest)
>> std::copy_backward (src.begin (), src.end (), dest.end ());
>> }
>>
>> +/* Replace all occurrences of a value in the provided range.
>> +
>> + Note: this helper is a reimplementation of std::replace, only available
>> + from C++20 onwards, and consequently, should be removed once we switch
>> + to C++20. */
>> +
>> +template <class ForwardIt, typename T>
>> +void replace (ForwardIt first, ForwardIt last,
>> + const T &old_value, const T &new_value)
>> +{
>> + for (auto it = first; it != last; ++it)
>> + {
>> + if (*it == old_value)
>> + *it = new_value;
>> + }
>> +}
>
> How does this differ from pre-C++20 std::replace?
>
> Kevin
>
I clearly misread the doc => https://en.cppreference.com/cpp/algorithm/replace
template< class ForwardIt, class T >
void replace( ForwardIt first, ForwardIt last,
const T& old_value, const T& new_value );
(1) (until C++26)
(constexpr since C++20)
It was not added in C++20 but became constexpr since C++20.
Since the range version was added in C++20, I must have mixed it up in my head.
I removed this duplicate from the patch, and made the range version use std::replace instead.
commit 8854b859aec1a3cbcd3edeb571dc1388ac5b81f7
Author: Matthieu Longo <matthieu.longo@arm.com>
Date: Fri Jul 3 16:02:13 2026 +0100
gdb support: add gdb::ranges::replace algorithm
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
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)
+{
+ std::replace (r.begin (), r.end (), old_value, new_value);
+}
+
+} /* namespace ranges */
+
/* Compare LHS and RHS for (deep) equality. That is, whether LHS and
RHS have the same sizes, and whether each pair of elements of LHS
and RHS at the same position compares equal. */
Matthieu.
next prev parent reply other threads:[~2026-07-13 15:54 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 15:48 [PATCH v1 00/10] gdb: bugfix 31207 and various refactoring in linux-tdep Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 01/10] gdb/linux-tdep: change linux_fill_prpsinfo to return bool Matthieu Longo
2026-07-09 6:26 ` Thiago Jung Bauermann
2026-07-09 12:23 ` Simon Marchi
2026-07-27 14:38 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 02/10] gdb: rely on the first alive thread TPID when reading Linux procfs files Matthieu Longo
2026-07-09 6:29 ` Thiago Jung Bauermann
2026-07-13 9:11 ` Matthieu Longo
2026-07-09 14:24 ` Simon Marchi
2026-07-14 15:47 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 03/10] target_fileio_read_stralloc: add an optional length parameter Matthieu Longo
2026-07-09 6:30 ` Thiago Jung Bauermann
2026-07-13 15:26 ` Matthieu Longo
2026-07-24 2:50 ` Thiago Jung Bauermann
2026-07-27 14:52 ` Matthieu Longo
2026-07-29 1:57 ` Thiago Jung Bauermann
2026-07-21 21:28 ` Luis
2026-07-27 14:48 ` Matthieu Longo
2026-07-27 14:53 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 04/10] gdb support: add gdb::replace algorithm for iterators and ranges Matthieu Longo
2026-07-09 6:30 ` Thiago Jung Bauermann
2026-07-10 21:21 ` Kevin Buettner
2026-07-13 15:51 ` Matthieu Longo [this message]
2026-07-21 21:33 ` Luis
2026-07-27 14:58 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 05/10] gdb: introduce helper class file_reader_t Matthieu Longo
2026-07-09 6:33 ` Thiago Jung Bauermann
2026-07-13 17:17 ` Matthieu Longo
2026-07-10 21:43 ` Kevin Buettner
2026-07-13 16:31 ` Matthieu Longo
2026-07-13 15:50 ` Schimpe, Christina
2026-07-13 17:12 ` Matthieu Longo
2026-07-22 16:36 ` Joos, Christina
2026-07-27 15:13 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 06/10] gdb/linux-tdep: migrate linux_info_proc to file_reader_t Matthieu Longo
2026-07-09 6:35 ` Thiago Jung Bauermann
2026-07-13 17:20 ` Matthieu Longo
2026-07-21 21:43 ` Luis
2026-07-27 17:11 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 07/10] gdb/linux-tdep: migrate linux_find_memory_regions_full " Matthieu Longo
2026-07-09 6:36 ` Thiago Jung Bauermann
2026-07-14 8:40 ` Matthieu Longo
2026-07-24 2:51 ` Thiago Jung Bauermann
2026-07-21 21:47 ` Luis
2026-07-27 17:14 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 08/10] gdb/linux-tdep: migrate parse_smaps_data " Matthieu Longo
2026-07-09 6:41 ` Thiago Jung Bauermann
2026-07-14 8:49 ` Matthieu Longo
2026-07-24 2:52 ` Thiago Jung Bauermann
2026-07-21 21:49 ` Luis
2026-07-27 17:17 ` Matthieu Longo
2026-07-07 15:48 ` [PATCH v1 09/10] gdb/linux-tdep: parse ProtectionKey in /proc/PID/smaps Matthieu Longo
2026-07-09 6:42 ` Thiago Jung Bauermann
2026-07-14 9:12 ` Matthieu Longo
2026-07-14 9:29 ` Matthieu Longo
2026-07-24 2:58 ` Thiago Jung Bauermann
2026-07-24 10:27 ` Yury Khrustalev
2026-07-25 6:40 ` Thiago Jung Bauermann
2026-07-27 8:22 ` Yury Khrustalev
2026-07-29 1:10 ` Thiago Jung Bauermann
2026-07-21 21:57 ` Luis
2026-07-27 17:54 ` Matthieu Longo
2026-07-07 15:49 ` [PATCH v1 10/10] gdb/linux: add helpers to read AT_HWCAP3 and AT_HWCAP4 Matthieu Longo
2026-07-09 6:44 ` Thiago Jung Bauermann
2026-07-21 21:58 ` Luis
2026-07-27 17:32 ` 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=77b1efaf-3a30-4663-87f3-ea3814c54474@arm.com \
--to=matthieu.longo@arm.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=kevinb@redhat.com \
--cc=luis.machado.foss@gmail.com \
--cc=luis.machado@amd.com \
--cc=pedro@palves.net \
--cc=tom@tromey.com \
--cc=yury.khrustalev@arm.com \
/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