This is the mail archive of the
mailing list for the GCC project.
Re: [libstdc++] Add C++17clamp
- From: NightStrike <nightstrike at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: Ed Smith-Rowland <3dw4rd at verizon dot net>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 22 Jul 2016 17:12:28 -0400
- Subject: Re: [libstdc++] Add C++17clamp
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <CAF1jjLs8iD0Bj3DjQARRhWiwb8YETPefz=Le43FPgnayLQxj+Q@mail.gmail.com> <20160722075142.GJ4264@redhat.com> <20160722075534.GK4264@redhat.com>
Would it be possible to fix the missed optimization to give the better
asm without having to do -ffast-math as mentioned here:
If so, then the proposed implementation would be optimized for the simple case.
On Fri, Jul 22, 2016 at 3:55 AM, Jonathan Wakely <firstname.lastname@example.org> wrote:
> On 22/07/16 08:51 +0100, Jonathan Wakely wrote:
>> On 21/07/16 19:38 -0400, NightStrike wrote:
>>> On Thu, Jul 14, 2016 at 7:50 PM, Ed Smith-Rowland <email@example.com>
>>>> Here is an implementation of P0025
>>>> An algorithm to "clamp" a value between a pair of boundary values.
>>>> Testing is almost finished - looks good so far.
>>>> OK if testing passes?
>>>> I didn't see a feature test in any of the SD-6 papers or P0025.
>>> This is not an efficient implementation. See here:
>>> Which I derived from this SO answer (which is sadly not the accepted
>>> answer at this time):
>>> I suggest using the very efficient method that requires a temporary.
>> That isn't a valid implementation of std::clamp, since it performs a
>> copy. The template argument might not even be copyable.
> We could possibly dispatch to such an implementation for arithmetic
> types, but we wouldn't want to do it for all copyable types. There's
> no way you can know whether making that local copy is expensive for an
> arbitrary type, and making a copy isn't allowed anyway.