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

Hello Anteru, Yes, there exist several overloads of abs() functions or similar but some of them with different name, say fabs, fabsf, etc. This make it impossible to use it in generic code. More specifically, I've ever written this code cout << std::abs<int>(-1) << endl; but, to my very surprise, I get 0! I have #include <cmath> #include <cstdlib> I'm using VS2003SP1 under WinXP_SP1 Thanks B/Rgds Max ----- Original Message ----- From: Anteru To: boost-users@lists.boost.org Subject: Re: [Boost-users] [STL] Is there a std::abs<>() function? Date: 2008-12-23 19:00:56 Max schrieb:
Hello,
It's strange to me that there seems not to be a std::abs<>() function in STL, with it I can write code like this:
double d = std::abs(-1.0); int i = std::abs(-1);
Does anybody else have the same feeling?
#include double d = std::abs (-1.0); cmath pulls the standard math functions into the std namespace, and adds a few overloads. See for example: http://www.dinkumware.com/manuals/?manual=compleat&page=math.html#abs Cheers, Anteru ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )

On Tue, Dec 23, 2008 at 19:34, Max
Yes, there exist several overloads of abs() functions or similar but some of them with different name, say fabs, fabsf, etc. This make it impossible to use it in generic code.
With the C++ headers, they're all available as std::abs (26.5 [lib.c.math]).
participants (2)
-
Max
-
Scott McMurray