Re: [Boost-users] [STL] Is there a std::abs<>() function? (Max)

seconded. But could you tell me where I can find the temple version of AbsoluteValue function you mentioned? Thanks B/Rgds 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-23 23:28:08 Scott McMurray wrote:
On Mon, Dec 22, 2008 at 21:06, Max wrote:
What I need is a template version of abs, not the
int abs(int) function, to make use of it genericly.
Do you really need a template of it? I can't see why using ADL
wouldn't be enough (with a using declaration for std::abs, to catch
the overloads for scalars from and ).
I certainly use template versions of Max, Min, and AbsoluteValue, because I need them for user-defined classes (that represent real numbers) and not just for built-in types. ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )

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
----- 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-23 23:28:08
Scott McMurray wrote:
On Mon, Dec 22, 2008 at 21:06, Max wrote:
What I need is a template version of abs, not the
int abs(int) function, to make use of it genericly.
Do you really need a template of it? I can't see why using ADL
wouldn't be enough (with a using declaration for std::abs, to catch
the overloads for scalars from and ).
I certainly use template versions of Max, Min, and AbsoluteValue,
because I need them for user-defined classes (that represent real
numbers) and not just for built-in types.
------------------------------------------------------------------- ���˿ռ䡪�������ѿ��ķ������������(http://space.sina.com.cn/ )
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Deane Yang
-
Max