Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2011-09-26 13:10:08


On 26 September 2011 10:12, Olaf van der Spek <ml_at_[hidden]> wrote:

> On Mon, Sep 26, 2011 at 5:04 PM, Christian Holmquist
> <c.holmquist_at_[hidden]> wrote:
> >> Is this really the fault of clamp() though?
> >>
> > No, but clamp can avoid exposing this inherited problem, just as
> > std::min/std::max does.
>
> 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;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk