Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-09-24 10:31:05

On Fri, Sep 23, 2011 at 6:21 PM, Phil Endecott
<spam_from_boost_dev_at_[hidden]> wrote:
>  template<typename V>
>  V clamp ( V val, V lo, V hi );
> I have a clamp function that orders the args low - middle - high, which
> seems like a more natural ordering to me.  Is there some rationale or
> precedent for this middle - low - high ordering?  I think the confusion

lo and hi will often be short literals, while val might be longer.
Having lo and hi close together seems like a good idea.
If val is really long, it might even be better to have lo and hi
before val, as is sometimes seen with (if X == f()) where X is a

> I note that this function takes its args by value, while std::min & max take
> const references.  What is the rationale for this?

Probably just an oversight.

> compile, and (b) conversions from const char* to std::string will only
> happen when necessary, not unconditionally for all of the arguments.

I guess that depends on the optimizer. I've been wondering, are
compilers good enough nowadays to construct std::string from string
literals at compile-time?

On Sat, Sep 24, 2011 at 11:04 AM, John Bytheway
<jbytheway+boost_at_[hidden]> wrote:
> Yes, it does buy you something.  std::less defines a total ordering on
> pointers, operator< need not.  (See N3290 [comparisons] 20.8.5 p8)

I'm not sure clamping pointers is a good idea.


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