Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org, Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCH 1/3] gdbsupport: add gdb::enumerate util
Date: Fri, 20 Feb 2026 19:58:12 -0500	[thread overview]
Message-ID: <624018cf-a16d-46b8-8782-455d6023894a@efficios.com> (raw)
In-Reply-To: <87zf53ywe8.fsf@tromey.com>



On 2026-02-20 15:47, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
> Simon> Add a "enumerate" utility, that acts pretty much like Python's
> Simon> enumerate().  It makes the code slightly nicer, for when you would
> Simon> otherwise need to handle the counter by hand.
> 
> Very handy.
> 
> Simon> +namespace gdb
> Simon> +{
> Simon> +
> 
> I suggest adding more namespaces and calling this
> gdb::ranges::views::enumerate.  Then when gdb uses C++23, we can perhaps
> just s/gdb/std/ and not reformat everything.
> 
> https://en.cppreference.com/w/cpp/ranges/enumerate_view.html
> 
> ... in particular note (2)
> 
> I guess we could go the other way but I tend to think it's better in the
> end to just use the standard names and not supply renamings of things.

I don't have a strong opinion about this, but I don't mind doing as you
propose.  It's just unfortunate that `gdb::ranges::views::enumerate` is
a bit verbose for nothing, but if this is what we'll have to use when we
get to C++23, then so be it.  Perhaps we will have increased the 80
character limit by then, who knows.

> Simon> +template<typename T>
> Simon> +struct enumerated_element
> Simon> +{
> Simon> +  std::size_t index;
> Simon> +  T value;
> Simon> +};
> 
> C++23 uses a tuple here.
> 
> It also uses a reference but I am not sure if that matters for us.

In my version it's also a reference because of:

  using value_type
    = enumerated_element<typename std::iterator_traits<base_iterator>
				    ::reference>;

We want it to be a reference in most cases, to avoid copying the value.

I can try to use a tuple.  It will probably not make a big difference,
because I expect all uses to use structured bindings:

  for ([i, v] : ...)

Thanks,

Simon

  reply	other threads:[~2026-02-21  0:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20 20:19 Simon Marchi
2026-02-20 20:19 ` [PATCH 2/3] gdb/dwarf: use enumerate in index-write.c Simon Marchi
2026-02-20 20:19 ` [PATCH 3/3] gdb: use enumerate in gdbtypes.c Simon Marchi
2026-02-20 20:47 ` [PATCH 1/3] gdbsupport: add gdb::enumerate util Tom Tromey
2026-02-21  0:58   ` Simon Marchi [this message]
2026-02-21  1:18 ` [PATCH v2 1/3] gdbsupport: add gdb::ranges::views::enumerate util simon.marchi
2026-02-21  1:18   ` [PATCH v2 2/3] gdb/dwarf: use enumerate in index-write.c simon.marchi
2026-02-21  1:19   ` [PATCH v2 3/3] gdb: use enumerate in gdbtypes.c simon.marchi
2026-03-14 17:32   ` [PATCH v2 1/3] gdbsupport: add gdb::ranges::views::enumerate util Simon Marchi
2026-04-16 19:52   ` Simon Marchi

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=624018cf-a16d-46b8-8782-455d6023894a@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=tom@tromey.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