https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100249

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to 康桓瑋 from comment #5)
> (In reply to Patrick Palka from comment #4)
> > (In reply to 康桓瑋 from comment #0)
> > > when the type of __proj_val is an rvalue reference, we need to convert it 
> > > to
> > > rvalue for the next std::__invoke call: https://godbolt.org/z/1G7aqxs3c.
> > 
> > So it seems the projection application limit of 3 makes it impossible for
> > ranges::clamp to perfectly support the case where the projection returns an
> > rvalue reference.
> 
> Maybe this can help:
> 
>   auto&& __proj_val = std::__invoke(__proj, __val);
>       if (std::__invoke(__comp,
> std::forward<decltype(__proj_val)>(__proj_val), std::__invoke(__proj, __lo)))
>         return __lo;

We could safely forward __proj_val only in the second invocation of __comp,
after which __proj_val is no longer used, but I'm not sure that's worthwhile...

Reply via email to