Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-09-23 15:01:58


On Fri, Sep 23, 2011 at 9:34 AM, Marshall Clow <mclow.lists_at_[hidden]>wrote:

>
> On Sep 23, 2011, at 9:21 AM, Phil Endecott wrote:
>
> > Dear All,
> >
> > Some quick comments about the proposed clamp() function:
>
[...]

> > Like min & max, clamp has a single type template parameter; what are the
> implications of this? For example, if I pass a mixture of std::string and
> const char* arguments, what will happen? Ideally, (a) all combinations would
> compile, and (b) conversions from const char* to std::string will only
> happen when necessary, not unconditionally for all of the arguments. (Maybe
> that is asking too much, though.)
>
> Dunno; I'll put it on the list of things to think about.
>

Isn't this *precisely* why we have common_type now? :)

I haven't actually looked at the documentation, but I'm gathering that
std::less<T> is the default comparison function object, in which case I
would suggest this should be replaced with some other function object with a
templated operator() that wraps operator<; this should avoid unnecessary
temporaries in more cases.

FWIW, I also share Phil's view that (lower, x, upper) is a more natural
ordering, but based on Robert's research, it looks like (x, lower, upper) is
more common and arguable precedented. It is unfortunate that it is very
easy to get the ordering confused, though :(

- Jeff


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