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

Simon Marchi
2025-08-29T16:01:44Z

On 2025-08-29 09:40, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
>
> Simon> It's currently not possible to use filtered_iterator with a pointer as
> Simon> the base iterator type. This patch makes it possible.
>
> I have a question about the forwarding constructor.
>
> Simon> + using iterator_category =
> Simon> + typename std::iterator_traits<BaseIterator>::iterator_category;
> Simon> + ;
> Simon> + using difference_type =
> Simon> + typename std::iterator_traits<BaseIterator>::difference_type;
> Simon> + ;
>
> Couple of random ";" there.

Oops, thanks, assignment operators were misplaced too.

> Simon> @@ -44,6 +46,10 @@ class filtered_iterator
> Simon> : m_it (std::forward<Args> (args)...)
> Simon> { skip_filtered (); }
>
> It seems to me that the presence of this constructor means that some
> existing code could change meaning. It's not really likely but I wonder
> how we would know.

Yeah, you're right. For the meaning of a call site to change, that call
site would need:

- a BaseIterator that can be constructed from two arguments A and B
(the existing constructor of filtered_iterator would then be called)
- that same BaseIterator can be constructed from the single argument A, and
also from the single argument B (the new constructor of
filtered_iterator would then be called)

I don't know how to know for sure whether this happens.

> I also wonder what this constructor is even needed for since it seems
> like a filtered iterator should just wrap an ordinary one anyway.

I think it's just a shortcut to have less boilerplate when you need to
instantiate a filtered_iterator. I think I would prefer having just the
begin/end version, so that there is less magic involved, making it
easier to debug compilation errors, at the expense of having to be more
explicit at the call sites. I think I tried it in a previous iteration
of this series and gave up, but if you think it's a good idea, I can try
it again.

Simon