[PATCH][V2] Reimplement __gnu_cxx::__ops operators
Jonathan Wakely
jwakely@redhat.com
Thu Sep 11 17:16:44 GMT 2025
On Thu, 11 Sept 2025 at 18:09, François Dumont wrote:
>
> On 9/11/25 11:34, Jonathan Wakely wrote:
> > Tomasz has convinced me that passing functors by reference internally
> > is a bad idea. For a stateful functor that contains something like an
> > integer or a pointer (e.g. a lambda with captured values, or just a
> > trivially-copyable struct with a non-static data member) passing it by
> > reference adds another indirection when invoking the functor. If we
> > pass by value, then it's just a simple copy that can be passed in a
> > register, and then invoking it is cheap.
> Looks like I can just close my PR then.
> >
> > For heavyweight functors that are not cheap to copy, users can pass
> > them into the algorithm with std::ref(cmp) if they need to avoid
> > copies.
> >
> Why doing this for the different std::erase_if implementations when
> invoking std::__remove_if but nowhere else ?
>
> This is the main reason why I did this change. Those usages made me
> considered that passing functors by value was bad and so used
> std::forward internally.
>
> Maybe those calls should be removed avoiding refwrap.h include in
> different places (and so adding the missing header in
> src/c++17/memory_resource.cc).
Yes, I think we should remove them from the erase_if functions.
More information about the Libstdc++
mailing list