Re: [PATCH 2/3] gdbsupport: make filtered_iterator work with pointers

Simon Marchi
2025-08-29T18:00:04Z

On 2025-08-29 09:40, Tom Tromey wrote:
> I also wonder what this constructor is even needed for since it seems
> like a filtered iterator should just wrap an ordinary one anyway.

To answer to that specifically: filtered_iterator needs to know the end
in addition to the begin, so that it knows when to stop advancing, in
operator++.

The goal of these variadic constructors is so that you don't need to be
explicit about all the iterator layers. To build a
filtered_iterator<my_iterator>, instead of writing:

filtered_iterator<my_iterator> (my_iterator (arg1, arg2))

You can write:

filtered_iterator<my_iterator> (arg1, arg2);

In my experience, it has been very confusing to work with these
iterators though. Compilation failures are hard to debug, like finding
which of the N layers of iterator is not happy. The complicated
template error messages certainly don't help. So I would propose to
ditch all those, and just have explicit and straightforward constructors
like the one I add in this patch. The code that uses these iterators
will be more explicit and larger, but typically we only write it once in
a factory function (e.g. all_threads).

Simon