
26 Sep
2011
26 Sep
'11
5:51 p.m.
Le 26/09/11 13:36, Dave Abrahams a écrit :
Note: you can solve that problem by asking the caller to do the conversion ;-)
I'm not sure this could always be the desired interface for the caller. When I want to clip an 22 bit integer to a 16 bit integer, I expect the result be a 16 bit integer. So in these cases the result type will be the types of lo and hi. int v; short lo,hi; short res= clamp(v, lo,hi); And in this case I can not convert the 22 bits integer to a 16 bit because I would lost some essential information. short res= clamp(short(v), lo,hi); // not the expected behavior That means that I will need to convert to the short res= short(clamp(v, int(lo),int(hi))); Best, Vicente