Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-09-26 13:33:18

On Mon, Sep 26, 2011 at 7:10 PM, Christian Holmquist
<c.holmquist_at_[hidden]> wrote:
>> min and max have two 'equivalent' parameters. clamp doesn't, it has
>> two limits and another argument. The return type is clear, it's the
>> type of the first argument, that's not the case for min and max.
> Why is the result type the first argument, since any of the three may be
> returned?
> Why is that clear for clamp?
> clamp(T x, Low lo, High hi)
> if (x < lo)
>  return lo;
>            ^---------- doesn't return T.
> else if (!(x < hi))
>  return hi;
>            ^---------- doesn't return T.
> else
>  return x;

Because I think the major use case is like clamp(X, -180, 180), where
the limits are fixed and the first argument isn't.

For example, "clamp1(short(), -5, 5);" doesn't compile: "no matching
function for call to ‘clamp1(short int, int, int)’"


Boost list run by bdawes at, gregod at, cpdaniel at, john at