Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2011-09-26 06:59:31

Christian Holmquist wrote:
> Since std::min/max takes one type (for good reasons), I don't see why clamp
> all of a sudden should be different.

Because it's faster.

> I would go for something like this...
> template<class T>
> T const & clamp(T const& x, T const& lo, T const &hi)
> {
> return std::min(std::max(x, lo), hi);
> }

That does an extra unnecessary comparison in the case when x < lo.

Regards, Phil.

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