
On Mon, Sep 26, 2011 at 7:10 PM, Christian Holmquist <c.holmquist@gmail.com> wrote:
min and max have two 'equivalent' parameters. clamp doesn't, it has two limits and another argument. The return type is clear, it's the type of the first argument, that's not the case for min and max.
Why is the result type the first argument, since any of the three may be returned?
Why is that clear for clamp? clamp(T x, Low lo, High hi) if (x < lo) return lo; ^---------- doesn't return T. else if (!(x < hi)) return hi; ^---------- doesn't return T. else return x;
Because I think the major use case is like clamp(X, -180, 180), where the limits are fixed and the first argument isn't. For example, "clamp1(short(), -5, 5);" doesn't compile: "no matching function for call to ‘clamp1(short int, int, int)’" Olaf