Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: "Harvey" <harveyab@xxxxxxxx>
- Date: 26 Feb 2007 03:22:19 -0800
On Feb 26, 2:47 am, David Wilkinson <no-re...@xxxxxxxxxxxx> wrote:
MrAsm wrote:
<CODE>
template <typename T>
T Clamp( T lower, T x, T upper )
{
if ( x < lower )
return lower;
else if ( x > upper )
return upper;
else
return x;
}
Mr Asm:
I would prefer to use const T& (like std::min() and std::max() do). I
would also get rid of the else's:
template <typename T>
const T& Clamp( const T& lower, const T& x, const T& upper )
{
if ( x < lower )
return lower;
if ( x > upper )
return upper;
return x;
}
What does the very first 'const' do?
Thanks for the suggestions, David.
Harvey
.
- Follow-Ups:
- Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: David Wilkinson
- Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: MrAsm
- Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- References:
- Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: Harvey
- Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: MrAsm
- Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- From: David Wilkinson
- Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- Prev by Date: Re: Does VC++ 6.0 support templates well?
- Next by Date: Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- Previous by thread: Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- Next by thread: Re: Function f(lb,x,ub); equivalent to min(ub,max(lb,x)); ?
- Index(es):
Relevant Pages
|