Add three way lower_bound

Jonathan Wakely jwakely.gcc@gmail.com
Thu Sep 1 06:47:55 GMT 2022


On Wed, 23 Jun 2021, 21:34 François Dumont via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

> Hi
>
> Following the message to propose an alternative lower_bound and the
> reply to use three way comparison I try to implement this.
>
> Before going further I wonder if this is something possible ?
>
> The purpose of the:
>
> if constexpr (three_way_comparable<>)
>
> is to make sure that we use it only if there is a proper <=> operator
> defined. Afai understood what is in <compare> we can have the
> __synth3way for any type as long as < exist. But I think that if <=> is
> implemented in terms of < then it might be too expensive, the actual
> lower_bound might already be implemented this way.
>
> My main concerns is of course Standard conformity, could it be ok ?
>


I don't think so. For a built-in type like int I don't think using <=> will
be faster. For a class type type with overloaded operator< it's observable
whether it gets called or not, so this patch would be a change in
observable behaviour. I think we have to use < instead.


> François
>
>


More information about the Libstdc++ mailing list