Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-09-23 12:34:16

On Sep 23, 2011, at 9:21 AM, Phil Endecott wrote:

> Dear All,
> Some quick comments about the proposed clamp() function:
> 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 matters in this case because type checking won't help to detect mistakes, and in the most obvious applications (e.g. sanitising input) it might be hard to spot an error. (In contrast, max(low,min(mid,high)) is unambiguous and not much more typing...)

Phil --

I'm not saying you're wrong - but you might want to look at:

where this discussion played out in the past.

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

Weird. I could have sworn I made it match what min/max did.
Opening a github ticket - thanks.

> 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.

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

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