On Thu, 20 Mar 2025 at 21:27, James K. Lowden <jklow...@schemamania.org> wrote:
>
> On Wed, 19 Mar 2025 20:33:36 +0000
> Jonathan Wakely <jwak...@redhat.com> wrote:
>
> > There's no need to keep using std::find_if from the beginning of the
> > container after every removal, just update the iterator after erasing
> > an element.
> >
> > This is how C++20 std::erase_if is implemented.\
>
> LGTM.  I am gun-shy about using iterators while modifying containers.
> I know there are rules.  :-/

Yes, the erased iterator is invalidated, but it returns an iterator to
the next element after the erased one, so we can continue iterating
from there instead of using the no-invalid one. That's what the
p=erase(p) patter does.
The important thing is to _not_ increment in that case, because
erasing *p and then pointing to the next element replaces the
increment.

> Likely you'll find other examples.  The arrays are small and the
> performance impact is too, but neatness counts and simpler is better.
>
> Jonathan, if your patches to the FE so far are awaiting *my* approval,
> consider it done.  I've read them and they're straightforward.  If I
> need to do more than just say that, please direct me.

OK, thanks. On that topic, should you be listed in the MAINTAINERS
file? I see Bob in there, but don't see your name.

I won't make the changes to use 'auto' which Bob didn't like. I'll
send another patch with a more minimal change for the remove_if call
using isspace.

Reply via email to