
26 Sep
2011
26 Sep
'11
10:59 a.m.
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.