
24 Sep
2011
24 Sep
'11
8:58 p.m.
Some quick comments about the proposed clamp() function:
template<typename V> V clamp ( V val, V lo, V hi );
Like min and max, you might consider algorithms that clamp ranges of values to a lo/hi pair. You could have clamp() that takes an initializer list and clamp_range that takes a pair of iterators. Of course, those would work in-place, so I wonder if Jefferey's suggestion for an in-place variant on a single value might also be good. That might give some other data points for thinking about the design of the interface. Personally, I think what you have now is the right signature.