In my opinion, the self-made version in my initial post
is probably superior than yours. :-P
which is repeated as follows:
#include
// my abs function
// it works not only for POD types, but also for
// user types that are default constructible and
// support operator<() and unary operator-()
template<class T> T abs(const T & x)
{
static boost::value_initialized<T> zero;
return (x < zero? -x : x);
}
Max
----- Original Message -----
From: Deane Yang
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [STL] Is there a std::abs<>() function? (Max)
Date: 2008-12-25 18:09:26
I just made up my own naive version. Improvements would be welcome:
template<typename T>
inline
T AbsoluteValue(const T& x)
{
if (x < T(0))
{
return -x;
}
else
{
return x;
}
}
Max wrote:
seconded.
But could you tell me where I can find the temple version of
AbsoluteValue function you mentioned?
Thanks
B/Rgds
Max
-------------------------------------------------------------------
新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )