Re: [PATCH 1/3] gdbsupport: add gdb::enumerate util

Tom Tromey
2026-02-20T20:48:31Z

>>>>> "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.

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.

Tom